123170Smckusick /* 233453Skarels * Copyright (c) 1982,1986,1988 Regents of the University of California. 333453Skarels * All rights reserved. 423170Smckusick * 533453Skarels * Redistribution and use in source and binary forms are permitted 633453Skarels * provided that this notice is preserved and that due credit is given 733453Skarels * to the University of California at Berkeley. The name of the University 833453Skarels * may not be used to endorse or promote products derived from this 933453Skarels * software without specific prior written permission. This software 1033453Skarels * is provided ``as is'' without express or implied warranty. 1133453Skarels * 12*34509Skarels * @(#)raw_imp.c 7.3 (Berkeley) 05/26/88 1323170Smckusick */ 145637Sroot 1517069Sbloom #include "param.h" 1617069Sbloom #include "mbuf.h" 1717069Sbloom #include "socket.h" 1817069Sbloom #include "protosw.h" 1917069Sbloom #include "socketvar.h" 2017069Sbloom #include "errno.h" 2110900Ssam 2210900Ssam #include "../net/if.h" 2313453Ssam #include "../net/route.h" 2410900Ssam #include "../net/raw_cb.h" 2510900Ssam 268401Swnj #include "../netinet/in.h" 278401Swnj #include "../netinet/in_systm.h" 2818414Skarels #include "../netinet/in_var.h" 2917069Sbloom #include "if_imp.h" 305637Sroot 315637Sroot /* 325637Sroot * Raw interface to IMP. 335637Sroot */ 345637Sroot 355637Sroot /* 365637Sroot * Generate IMP leader and pass packet to impoutput. 375637Sroot * The user must create a skeletal leader in order to 385637Sroot * communicate message type, message subtype, etc. 395637Sroot * We fill in holes where needed and verify parameters 405637Sroot * supplied by user. 415637Sroot */ 425847Sroot rimp_output(m, so) 435637Sroot register struct mbuf *m; 445637Sroot struct socket *so; 455637Sroot { 465637Sroot struct mbuf *n; 476509Ssam int len, error = 0; 485647Ssam register struct imp_leader *ip; 495637Sroot register struct sockaddr_in *sin; 505637Sroot register struct rawcb *rp = sotorawcb(so); 5118414Skarels struct in_ifaddr *ia; 525772Swnj struct control_leader *cp; 535637Sroot 545637Sroot /* 555637Sroot * Verify user has supplied necessary space 565637Sroot * for the leader and check parameters in it. 575637Sroot */ 585772Swnj if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct control_leader)) && 596509Ssam (m = m_pullup(m, sizeof(struct control_leader))) == 0) { 606509Ssam error = EMSGSIZE; /* XXX */ 616509Ssam goto bad; 626509Ssam } 635772Swnj cp = mtod(m, struct control_leader *); 645772Swnj if (cp->dl_mtype == IMPTYPE_DATA) 655772Swnj if (m->m_len < sizeof(struct imp_leader) && 666509Ssam (m = m_pullup(m, sizeof(struct imp_leader))) == 0) { 676509Ssam error = EMSGSIZE; /* XXX */ 686509Ssam goto bad; 696509Ssam } 705647Ssam ip = mtod(m, struct imp_leader *); 716509Ssam if (ip->il_format != IMP_NFF) { 726509Ssam error = EMSGSIZE; /* XXX */ 735637Sroot goto bad; 746509Ssam } 755870Sroot #ifdef notdef 765647Ssam if (ip->il_link != IMPLINK_IP && 776509Ssam (ip->il_link<IMPLINK_LOWEXPER || ip->il_link>IMPLINK_HIGHEXPER)) { 786509Ssam error = EPERM; 795637Sroot goto bad; 806509Ssam } 815870Sroot #endif 825637Sroot 835637Sroot /* 845637Sroot * Fill in IMP leader -- impoutput refrains from rebuilding 855637Sroot * the leader when it sees the protocol family PF_IMPLINK. 865637Sroot * (message size calculated by walking through mbuf's) 875637Sroot */ 885637Sroot for (len = 0, n = m; n; n = n->m_next) 895637Sroot len += n->m_len; 906161Ssam ip->il_length = htons((u_short)(len << 3)); 916509Ssam sin = (struct sockaddr_in *)&rp->rcb_faddr; 92*34509Skarels imp_addr_to_leader((struct control_leader *)ip, sin->sin_addr.s_addr); 936339Ssam /* no routing here */ 9418414Skarels ia = in_iaonnetof(in_netof(sin->sin_addr)); 9518414Skarels if (ia) 9618414Skarels return (impoutput(ia->ia_ifp, m, (struct sockaddr *)sin)); 976509Ssam error = ENETUNREACH; 985637Sroot bad: 995637Sroot m_freem(m); 1006509Ssam return (error); 1015637Sroot } 102