1 /* 2 * Copyright (c) 1982, 1986, 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * @(#)raw_imp.c 7.5 (Berkeley) 04/22/89 18 */ 19 20 #include "param.h" 21 #include "mbuf.h" 22 #include "socket.h" 23 #include "protosw.h" 24 #include "socketvar.h" 25 #include "errno.h" 26 27 #include "../net/if.h" 28 #include "../net/route.h" 29 #include "../net/raw_cb.h" 30 31 #include "../netinet/in.h" 32 #include "../netinet/in_systm.h" 33 #include "../netinet/in_var.h" 34 #include "../netinet/in_pcb.h" 35 #include "if_imp.h" 36 37 /* 38 * Raw interface to IMP. 39 */ 40 41 /* 42 * Generate IMP leader and pass packet to impoutput. 43 * The user must create a skeletal leader in order to 44 * communicate message type, message subtype, etc. 45 * We fill in holes where needed and verify parameters 46 * supplied by user. 47 */ 48 rimp_output(m, so) 49 register struct mbuf *m; 50 struct socket *so; 51 { 52 struct mbuf *n; 53 int len, error = 0; 54 register struct imp_leader *ip; 55 register struct sockaddr_in *sin; 56 register struct raw_inpcb *rp = sotorawinpcb(so); 57 struct in_ifaddr *ia; 58 struct control_leader *cp; 59 60 /* 61 * Verify user has supplied necessary space 62 * for the leader and check parameters in it. 63 */ 64 if ((m->m_len < sizeof(struct control_leader)) && 65 (m = m_pullup(m, sizeof(struct control_leader))) == 0) { 66 error = EMSGSIZE; /* XXX */ 67 goto bad; 68 } 69 cp = mtod(m, struct control_leader *); 70 if (cp->dl_mtype == IMPTYPE_DATA) 71 if (m->m_len < sizeof(struct imp_leader) && 72 (m = m_pullup(m, sizeof(struct imp_leader))) == 0) { 73 error = EMSGSIZE; /* XXX */ 74 goto bad; 75 } 76 ip = mtod(m, struct imp_leader *); 77 if (ip->il_format != IMP_NFF) { 78 error = EMSGSIZE; /* XXX */ 79 goto bad; 80 } 81 #ifdef notdef 82 if (ip->il_link != IMPLINK_IP && 83 (ip->il_link<IMPLINK_LOWEXPER || ip->il_link>IMPLINK_HIGHEXPER)) { 84 error = EPERM; 85 goto bad; 86 } 87 #endif 88 89 /* 90 * Fill in IMP leader -- impoutput refrains from rebuilding 91 * the leader when it sees the protocol family PF_IMPLINK. 92 * (message size calculated by walking through mbuf's) 93 */ 94 for (len = 0, n = m; n; n = n->m_next) 95 len += n->m_len; 96 ip->il_length = htons((u_short)(len << 3)); 97 sin = (struct sockaddr_in *)rp->rinp_rcb.rcb_faddr; 98 imp_addr_to_leader((struct control_leader *)ip, sin->sin_addr.s_addr); 99 /* no routing here */ 100 ia = in_iaonnetof(in_netof(sin->sin_addr)); 101 if (ia) 102 return (impoutput(ia->ia_ifp, m, (struct sockaddr *)sin)); 103 error = ENETUNREACH; 104 bad: 105 m_freem(m); 106 return (error); 107 } 108