1: /* 2: * Copyright (c) 1982, 1986 Regents of the University of California. 3: * All rights reserved. The Berkeley software License Agreement 4: * specifies the terms and conditions for redistribution. 5: * 6: * @(#)raw_imp.c 7.1 (Berkeley) 6/4/86 7: */ 8: 9: #include "param.h" 10: #include "mbuf.h" 11: #include "socket.h" 12: #include "protosw.h" 13: #include "socketvar.h" 14: #include "errno.h" 15: 16: #include "../net/if.h" 17: #include "../net/route.h" 18: #include "../net/raw_cb.h" 19: 20: #include "../netinet/in.h" 21: #include "../netinet/in_systm.h" 22: #include "../netinet/in_var.h" 23: #include "if_imp.h" 24: 25: /* 26: * Raw interface to IMP. 27: */ 28: 29: /* 30: * Generate IMP leader and pass packet to impoutput. 31: * The user must create a skeletal leader in order to 32: * communicate message type, message subtype, etc. 33: * We fill in holes where needed and verify parameters 34: * supplied by user. 35: */ 36: rimp_output(m, so) 37: register struct mbuf *m; 38: struct socket *so; 39: { 40: struct mbuf *n; 41: int len, error = 0; 42: register struct imp_leader *ip; 43: register struct sockaddr_in *sin; 44: register struct rawcb *rp = sotorawcb(so); 45: struct in_ifaddr *ia; 46: struct control_leader *cp; 47: 48: /* 49: * Verify user has supplied necessary space 50: * for the leader and check parameters in it. 51: */ 52: if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct control_leader)) && 53: (m = m_pullup(m, sizeof(struct control_leader))) == 0) { 54: error = EMSGSIZE; /* XXX */ 55: goto bad; 56: } 57: cp = mtod(m, struct control_leader *); 58: if (cp->dl_mtype == IMPTYPE_DATA) 59: if (m->m_len < sizeof(struct imp_leader) && 60: (m = m_pullup(m, sizeof(struct imp_leader))) == 0) { 61: error = EMSGSIZE; /* XXX */ 62: goto bad; 63: } 64: ip = mtod(m, struct imp_leader *); 65: if (ip->il_format != IMP_NFF) { 66: error = EMSGSIZE; /* XXX */ 67: goto bad; 68: } 69: #ifdef notdef 70: if (ip->il_link != IMPLINK_IP && 71: (ip->il_link<IMPLINK_LOWEXPER || ip->il_link>IMPLINK_HIGHEXPER)) { 72: error = EPERM; 73: goto bad; 74: } 75: #endif 76: 77: /* 78: * Fill in IMP leader -- impoutput refrains from rebuilding 79: * the leader when it sees the protocol family PF_IMPLINK. 80: * (message size calculated by walking through mbuf's) 81: */ 82: for (len = 0, n = m; n; n = n->m_next) 83: len += n->m_len; 84: ip->il_length = htons((u_short)(len << 3)); 85: sin = (struct sockaddr_in *)&rp->rcb_faddr; 86: imp_addr_to_leader(ip, sin->sin_addr.s_addr); /* BRL */ 87: /* no routing here */ 88: ia = in_iaonnetof(in_netof(sin->sin_addr)); 89: if (ia) 90: return (impoutput(ia->ia_ifp, m, (struct sockaddr *)sin)); 91: error = ENETUNREACH; 92: bad: 93: m_freem(m); 94: return (error); 95: }