version 1.19, 1995/06/04 05:07:11 |
version 1.30, 1996/05/28 23:27:04 |
|
|
#include <sys/socketvar.h> |
#include <sys/socketvar.h> |
#include <sys/errno.h> |
#include <sys/errno.h> |
#include <sys/systm.h> |
#include <sys/systm.h> |
|
#include <sys/proc.h> |
|
|
#include <net/if.h> |
#include <net/if.h> |
#include <net/route.h> |
#include <net/route.h> |
|
|
#include <netinet/ip_var.h> |
#include <netinet/ip_var.h> |
#include <netinet/ip_mroute.h> |
#include <netinet/ip_mroute.h> |
#include <netinet/in_pcb.h> |
#include <netinet/in_pcb.h> |
|
#include <netinet/in_var.h> |
|
|
struct inpcb rawinpcb; |
#include <machine/stdarg.h> |
|
|
|
struct inpcbtable rawcbtable; |
|
|
|
int rip_bind __P((struct inpcb *, struct mbuf *)); |
|
int rip_connect __P((struct inpcb *, struct mbuf *)); |
|
void rip_disconnect __P((struct inpcb *)); |
|
|
/* |
/* |
* Nominal space allocated to a raw ip socket. |
* Nominal space allocated to a raw ip socket. |
|
|
rip_init() |
rip_init() |
{ |
{ |
|
|
rawinpcb.inp_next = rawinpcb.inp_prev = &rawinpcb; |
in_pcbinit(&rawcbtable, 1); |
} |
} |
|
|
struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET }; |
struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET }; |
Line 83 struct sockaddr_in ripsrc = { sizeof(rip |
|
Line 91 struct sockaddr_in ripsrc = { sizeof(rip |
|
* mbuf chain. |
* mbuf chain. |
*/ |
*/ |
void |
void |
rip_input(m) |
#if __STDC__ |
|
rip_input(struct mbuf *m, ...) |
|
#else |
|
rip_input(m, va_alist) |
struct mbuf *m; |
struct mbuf *m; |
|
va_dcl |
|
#endif |
{ |
{ |
register struct ip *ip = mtod(m, struct ip *); |
register struct ip *ip = mtod(m, struct ip *); |
register struct inpcb *inp; |
register struct inpcb *inp; |
struct socket *last = 0; |
struct socket *last = 0; |
|
|
ripsrc.sin_addr = ip->ip_src; |
ripsrc.sin_addr = ip->ip_src; |
for (inp = rawinpcb.inp_next; inp != &rawinpcb; inp = inp->inp_next) { |
for (inp = rawcbtable.inpt_queue.cqh_first; |
|
inp != (struct inpcb *)&rawcbtable.inpt_queue; |
|
inp = inp->inp_queue.cqe_next) { |
if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != ip->ip_p) |
if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != ip->ip_p) |
continue; |
continue; |
if (inp->inp_laddr.s_addr && |
if (inp->inp_laddr.s_addr != INADDR_ANY && |
inp->inp_laddr.s_addr != ip->ip_dst.s_addr) |
inp->inp_laddr.s_addr != ip->ip_dst.s_addr) |
continue; |
continue; |
if (inp->inp_faddr.s_addr && |
if (inp->inp_faddr.s_addr != INADDR_ANY && |
inp->inp_faddr.s_addr != ip->ip_src.s_addr) |
inp->inp_faddr.s_addr != ip->ip_src.s_addr) |
continue; |
continue; |
if (last) { |
if (last) { |
struct mbuf *n; |
struct mbuf *n; |
if (n = m_copy(m, 0, (int)M_COPYALL)) { |
if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) { |
if (sbappendaddr(&last->so_rcv, |
if (sbappendaddr(&last->so_rcv, |
sintosa(&ripsrc), n, |
sintosa(&ripsrc), n, |
(struct mbuf *)0) == 0) |
(struct mbuf *)0) == 0) |
|
|
* Tack on options user may have setup with control call. |
* Tack on options user may have setup with control call. |
*/ |
*/ |
int |
int |
rip_output(m, so, dst) |
#if __STDC__ |
register struct mbuf *m; |
rip_output(struct mbuf *m, ...) |
struct socket *so; |
#else |
u_long dst; |
rip_output(m, va_alist) |
|
struct mbuf *m; |
|
va_dcl |
|
#endif |
{ |
{ |
|
register struct inpcb *inp; |
register struct ip *ip; |
register struct ip *ip; |
register struct inpcb *inp = sotoinpcb(so); |
|
struct mbuf *opts; |
struct mbuf *opts; |
int flags = (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST; |
int flags; |
|
va_list ap; |
|
|
|
va_start(ap, m); |
|
inp = va_arg(ap, struct inpcb *); |
|
va_end(ap); |
|
|
|
flags = |
|
(inp->inp_socket->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST; |
|
|
/* |
/* |
* If the user handed us a complete IP packet, use it. |
* If the user handed us a complete IP packet, use it. |
Line 154 rip_output(m, so, dst) |
|
Line 180 rip_output(m, so, dst) |
|
ip->ip_p = inp->inp_ip.ip_p; |
ip->ip_p = inp->inp_ip.ip_p; |
ip->ip_len = m->m_pkthdr.len; |
ip->ip_len = m->m_pkthdr.len; |
ip->ip_src = inp->inp_laddr; |
ip->ip_src = inp->inp_laddr; |
ip->ip_dst.s_addr = dst; |
ip->ip_dst = inp->inp_faddr; |
ip->ip_ttl = MAXTTL; |
ip->ip_ttl = MAXTTL; |
opts = inp->inp_options; |
opts = inp->inp_options; |
} else { |
} else { |
Line 180 rip_ctloutput(op, so, level, optname, m) |
|
Line 206 rip_ctloutput(op, so, level, optname, m) |
|
struct mbuf **m; |
struct mbuf **m; |
{ |
{ |
register struct inpcb *inp = sotoinpcb(so); |
register struct inpcb *inp = sotoinpcb(so); |
register int error; |
#ifdef MROUTING |
|
int error; |
|
#endif |
|
|
if (level != IPPROTO_IP) { |
if (level != IPPROTO_IP) { |
if (m != 0 && *m != 0) |
if (m != 0 && *m != 0) |
Line 238 rip_ctloutput(op, so, level, optname, m) |
|
Line 266 rip_ctloutput(op, so, level, optname, m) |
|
return (ip_ctloutput(op, so, level, optname, m)); |
return (ip_ctloutput(op, so, level, optname, m)); |
} |
} |
|
|
|
int |
|
rip_bind(inp, nam) |
|
struct inpcb *inp; |
|
struct mbuf *nam; |
|
{ |
|
struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *); |
|
|
|
if (nam->m_len != sizeof(*addr)) |
|
return (EINVAL); |
|
if (ifnet.tqh_first == 0) |
|
return (EADDRNOTAVAIL); |
|
if (addr->sin_family != AF_INET && |
|
addr->sin_family != AF_IMPLINK) |
|
return (EAFNOSUPPORT); |
|
if (addr->sin_addr.s_addr != INADDR_ANY && |
|
ifa_ifwithaddr(sintosa(addr)) == 0) |
|
return (EADDRNOTAVAIL); |
|
inp->inp_laddr = addr->sin_addr; |
|
return (0); |
|
} |
|
|
|
int |
|
rip_connect(inp, nam) |
|
struct inpcb *inp; |
|
struct mbuf *nam; |
|
{ |
|
struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *); |
|
|
|
if (nam->m_len != sizeof(*addr)) |
|
return (EINVAL); |
|
if (ifnet.tqh_first == 0) |
|
return (EADDRNOTAVAIL); |
|
if (addr->sin_family != AF_INET && |
|
addr->sin_family != AF_IMPLINK) |
|
return (EAFNOSUPPORT); |
|
inp->inp_faddr = addr->sin_addr; |
|
return (0); |
|
} |
|
|
|
void |
|
rip_disconnect(inp) |
|
struct inpcb *inp; |
|
{ |
|
|
|
inp->inp_faddr.s_addr = INADDR_ANY; |
|
} |
|
|
u_long rip_sendspace = RIPSNDQ; |
u_long rip_sendspace = RIPSNDQ; |
u_long rip_recvspace = RIPRCVQ; |
u_long rip_recvspace = RIPRCVQ; |
|
|
/*ARGSUSED*/ |
/*ARGSUSED*/ |
int |
int |
rip_usrreq(so, req, m, nam, control) |
rip_usrreq(so, req, m, nam, control, p) |
register struct socket *so; |
register struct socket *so; |
int req; |
int req; |
struct mbuf *m, *nam, *control; |
struct mbuf *m, *nam, *control; |
|
struct proc *p; |
{ |
{ |
|
register struct inpcb *inp; |
|
int s; |
register int error = 0; |
register int error = 0; |
register struct inpcb *inp = sotoinpcb(so); |
|
#ifdef MROUTING |
#ifdef MROUTING |
extern struct socket *ip_mrouter; |
extern struct socket *ip_mrouter; |
#endif |
#endif |
|
|
|
if (req == PRU_CONTROL) |
|
return (in_control(so, (long)m, (caddr_t)nam, |
|
(struct ifnet *)control, p)); |
|
|
|
s = splsoftnet(); |
|
inp = sotoinpcb(so); |
|
#ifdef DIAGNOSTIC |
|
if (req != PRU_SEND && req != PRU_SENDOOB && control) |
|
panic("rip_usrreq: unexpected control mbuf"); |
|
#endif |
|
if (inp == 0 && req != PRU_ATTACH) { |
|
error = EINVAL; |
|
goto release; |
|
} |
|
|
switch (req) { |
switch (req) { |
|
|
case PRU_ATTACH: |
case PRU_ATTACH: |
if (inp) |
if (inp != 0) { |
panic("rip_attach"); |
error = EISCONN; |
if ((so->so_state & SS_PRIV) == 0) { |
break; |
|
} |
|
if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag))) { |
error = EACCES; |
error = EACCES; |
break; |
break; |
} |
} |
if ((error = soreserve(so, rip_sendspace, rip_recvspace)) || |
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { |
(error = in_pcballoc(so, &rawinpcb))) |
error = soreserve(so, rip_sendspace, rip_recvspace); |
|
if (error) |
|
break; |
|
} |
|
error = in_pcballoc(so, &rawcbtable); |
|
if (error) |
break; |
break; |
inp = (struct inpcb *)so->so_pcb; |
inp = sotoinpcb(so); |
inp->inp_ip.ip_p = (long)nam; |
inp->inp_ip.ip_p = (long)nam; |
break; |
break; |
|
|
case PRU_DISCONNECT: |
|
if ((so->so_state & SS_ISCONNECTED) == 0) { |
|
error = ENOTCONN; |
|
break; |
|
} |
|
/* FALLTHROUGH */ |
|
case PRU_ABORT: |
|
soisdisconnected(so); |
|
/* FALLTHROUGH */ |
|
case PRU_DETACH: |
case PRU_DETACH: |
if (inp == 0) |
|
panic("rip_detach"); |
|
#ifdef MROUTING |
#ifdef MROUTING |
if (so == ip_mrouter) |
if (so == ip_mrouter) |
ip_mrouter_done(); |
ip_mrouter_done(); |
Line 289 rip_usrreq(so, req, m, nam, control) |
|
Line 378 rip_usrreq(so, req, m, nam, control) |
|
break; |
break; |
|
|
case PRU_BIND: |
case PRU_BIND: |
{ |
error = rip_bind(inp, nam); |
struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *); |
break; |
|
|
if (nam->m_len != sizeof(*addr)) { |
case PRU_LISTEN: |
error = EINVAL; |
error = EOPNOTSUPP; |
break; |
|
} |
|
if ((ifnet == 0) || |
|
((addr->sin_family != AF_INET) && |
|
(addr->sin_family != AF_IMPLINK)) || |
|
(addr->sin_addr.s_addr && |
|
ifa_ifwithaddr(sintosa(addr)) == 0)) { |
|
error = EADDRNOTAVAIL; |
|
break; |
|
} |
|
inp->inp_laddr = addr->sin_addr; |
|
break; |
break; |
} |
|
case PRU_CONNECT: |
|
{ |
|
struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *); |
|
|
|
if (nam->m_len != sizeof(*addr)) { |
case PRU_CONNECT: |
error = EINVAL; |
error = rip_connect(inp, nam); |
break; |
if (error) |
} |
|
if (ifnet == 0) { |
|
error = EADDRNOTAVAIL; |
|
break; |
|
} |
|
if ((addr->sin_family != AF_INET) && |
|
(addr->sin_family != AF_IMPLINK)) { |
|
error = EAFNOSUPPORT; |
|
break; |
break; |
} |
|
inp->inp_faddr = addr->sin_addr; |
|
soisconnected(so); |
soisconnected(so); |
break; |
break; |
} |
|
|
|
case PRU_CONNECT2: |
case PRU_CONNECT2: |
error = EOPNOTSUPP; |
error = EOPNOTSUPP; |
break; |
break; |
|
|
|
case PRU_DISCONNECT: |
|
soisdisconnected(so); |
|
rip_disconnect(inp); |
|
break; |
|
|
/* |
/* |
* Mark the connection as being incapable of further input. |
* Mark the connection as being incapable of further input. |
*/ |
*/ |
Line 340 rip_usrreq(so, req, m, nam, control) |
|
Line 408 rip_usrreq(so, req, m, nam, control) |
|
socantsendmore(so); |
socantsendmore(so); |
break; |
break; |
|
|
|
case PRU_RCVD: |
|
error = EOPNOTSUPP; |
|
break; |
|
|
/* |
/* |
* Ship a packet out. The appropriate raw output |
* Ship a packet out. The appropriate raw output |
* routine handles any massaging necessary. |
* routine handles any massaging necessary. |
*/ |
*/ |
case PRU_SEND: |
case PRU_SEND: |
{ |
if (control && control->m_len) { |
register u_int32_t dst; |
m_freem(control); |
|
m_freem(m); |
if (so->so_state & SS_ISCONNECTED) { |
error = EINVAL; |
if (nam) { |
break; |
|
} |
|
{ |
|
if (nam) { |
|
if ((so->so_state & SS_ISCONNECTED) != 0) { |
error = EISCONN; |
error = EISCONN; |
|
goto die; |
|
} |
|
error = rip_connect(inp, nam); |
|
if (error) { |
|
die: |
|
m_freem(m); |
break; |
break; |
} |
} |
dst = inp->inp_faddr.s_addr; |
|
} else { |
} else { |
if (nam == NULL) { |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
error = ENOTCONN; |
error = ENOTCONN; |
break; |
goto die; |
} |
} |
dst = mtod(nam, struct sockaddr_in *)->sin_addr.s_addr; |
|
} |
} |
error = rip_output(m, so, dst); |
error = rip_output(m, inp); |
m = NULL; |
if (nam) |
|
rip_disconnect(inp); |
|
} |
break; |
break; |
} |
|
|
|
case PRU_SENSE: |
case PRU_SENSE: |
/* |
/* |
* stat: don't bother with a blocksize. |
* stat: don't bother with a blocksize. |
*/ |
*/ |
|
splx(s); |
return (0); |
return (0); |
|
|
/* |
|
* Not supported. |
|
*/ |
|
case PRU_RCVOOB: |
case PRU_RCVOOB: |
case PRU_RCVD: |
error = EOPNOTSUPP; |
case PRU_LISTEN: |
break; |
case PRU_ACCEPT: |
|
case PRU_SENDOOB: |
case PRU_SENDOOB: |
|
m_freem(control); |
|
m_freem(m); |
error = EOPNOTSUPP; |
error = EOPNOTSUPP; |
break; |
break; |
|
|
Line 394 rip_usrreq(so, req, m, nam, control) |
|
Line 475 rip_usrreq(so, req, m, nam, control) |
|
default: |
default: |
panic("rip_usrreq"); |
panic("rip_usrreq"); |
} |
} |
if (m != NULL) |
|
m_freem(m); |
release: |
|
splx(s); |
return (error); |
return (error); |
} |
} |