123160Smckusick /* 229066Smckusick * Copyright (c) 1980, 1986 Regents of the University of California. 333183Sbostic * All rights reserved. 423160Smckusick * 533183Sbostic * Redistribution and use in source and binary forms are permitted 634844Sbostic * provided that the above copyright notice and this paragraph are 734844Sbostic * duplicated in all such forms and that any documentation, 834844Sbostic * advertising materials, and other materials related to such 934844Sbostic * distribution and use acknowledge that the software was developed 1034844Sbostic * by the University of California, Berkeley. The name of the 1134844Sbostic * University may not be used to endorse or promote products derived 1234844Sbostic * from this software without specific prior written permission. 1334844Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434844Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534844Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1633183Sbostic * 17*44413Skarels * @(#)raw_cb.c 7.10 (Berkeley) 06/28/90 1823160Smckusick */ 195635Sroot 2017066Sbloom #include "param.h" 2117066Sbloom #include "systm.h" 2217066Sbloom #include "mbuf.h" 2317066Sbloom #include "socket.h" 2417066Sbloom #include "socketvar.h" 2521769Skarels #include "domain.h" 2621769Skarels #include "protosw.h" 2717066Sbloom #include "errno.h" 2810890Ssam 2917066Sbloom #include "if.h" 3017066Sbloom #include "route.h" 3117066Sbloom #include "raw_cb.h" 3212783Ssam #include "../netinet/in.h" 335635Sroot 3437500Smckusick #include "machine/mtpr.h" 3510890Ssam 365635Sroot /* 375635Sroot * Routines to manage the raw protocol control blocks. 385635Sroot * 395635Sroot * TODO: 405635Sroot * hash lookups by protocol family/protocol + address family 416339Ssam * take care of unique address problems per AF? 426045Swnj * redo address binding to allow wildcards 435635Sroot */ 445635Sroot 4536823Skarels u_long raw_sendspace = RAWSNDQ; 4636823Skarels u_long raw_recvspace = RAWRCVQ; 4736823Skarels 485635Sroot /* 495635Sroot * Allocate a control block and a nominal amount 505635Sroot * of buffer space for the socket. 515635Sroot */ 5221769Skarels raw_attach(so, proto) 535635Sroot register struct socket *so; 5421769Skarels int proto; 555635Sroot { 5637472Ssklower register struct rawcb *rp = sotorawcb(so); 57*44413Skarels int error; 585635Sroot 5937472Ssklower /* 6037472Ssklower * It is assumed that raw_attach is called 6137472Ssklower * after space has been allocated for the 6237472Ssklower * rawcb. 6337472Ssklower */ 6437472Ssklower if (rp == 0) 655635Sroot return (ENOBUFS); 66*44413Skarels if (error = soreserve(so, raw_sendspace, raw_recvspace)) 67*44413Skarels return (error); 685635Sroot rp->rcb_socket = so; 6921769Skarels rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family; 7021769Skarels rp->rcb_proto.sp_protocol = proto; 7121769Skarels insque(rp, &rawcb); 725635Sroot return (0); 735635Sroot } 745635Sroot 755635Sroot /* 765635Sroot * Detach the raw connection block and discard 775635Sroot * socket resources. 785635Sroot */ 795635Sroot raw_detach(rp) 805635Sroot register struct rawcb *rp; 815635Sroot { 825635Sroot struct socket *so = rp->rcb_socket; 835635Sroot 845635Sroot so->so_pcb = 0; 855635Sroot sofree(so); 865635Sroot remque(rp); 8737472Ssklower #ifdef notdef 8837472Ssklower if (rp->rcb_laddr) 8937472Ssklower m_freem(dtom(rp->rcb_laddr)); 9037472Ssklower rp->rcb_laddr = 0; 9137472Ssklower #endif 9237472Ssklower free((caddr_t)(rp), M_PCB); 935635Sroot } 945635Sroot 955635Sroot /* 965635Sroot * Disconnect and possibly release resources. 975635Sroot */ 985635Sroot raw_disconnect(rp) 995635Sroot struct rawcb *rp; 1005635Sroot { 1018975Sroot 10237472Ssklower #ifdef notdef 10337472Ssklower if (rp->rcb_faddr) 10437472Ssklower m_freem(dtom(rp->rcb_faddr)); 10537472Ssklower rp->rcb_faddr = 0; 10637472Ssklower #endif 1077517Sroot if (rp->rcb_socket->so_state & SS_NOFDREF) 1085635Sroot raw_detach(rp); 1095635Sroot } 1105635Sroot 11137472Ssklower #ifdef notdef 1128394Swnj raw_bind(so, nam) 1138394Swnj register struct socket *so; 1148394Swnj struct mbuf *nam; 1158394Swnj { 1168394Swnj struct sockaddr *addr = mtod(nam, struct sockaddr *); 1178394Swnj register struct rawcb *rp; 1188394Swnj 1198394Swnj if (ifnet == 0) 1208394Swnj return (EADDRNOTAVAIL); 1219184Ssam rp = sotorawcb(so); 12237472Ssklower nam = m_copym(nam, 0, M_COPYALL, M_WAITOK); 12337472Ssklower rp->rcb_laddr = mtod(nam, struct sockaddr *); 1248394Swnj return (0); 1258394Swnj } 12637472Ssklower #endif 127