| version 1.25.4.1, 1996/11/10 21:57:53 |
version 1.25.4.2, 1996/12/11 04:01:08 |
|
|
| #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> |
|
|
| |
|
| struct inpcbtable rawcbtable; |
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. |
| */ |
*/ |
| Line 104 rip_input(m, va_alist) |
|
| Line 109 rip_input(m, va_alist) |
|
| inp = inp->inp_queue.cqe_next) { |
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) { |
| Line 150 rip_output(m, va_alist) |
|
| Line 155 rip_output(m, va_alist) |
|
| va_dcl |
va_dcl |
| #endif |
#endif |
| { |
{ |
| struct socket *so; |
|
| u_long dst; |
|
| register struct ip *ip; |
|
| register struct inpcb *inp; |
register struct inpcb *inp; |
| |
register struct ip *ip; |
| struct mbuf *opts; |
struct mbuf *opts; |
| int flags; |
int flags; |
| va_list ap; |
va_list ap; |
| |
|
| va_start(ap, m); |
va_start(ap, m); |
| so = va_arg(ap, struct socket *); |
inp = va_arg(ap, struct inpcb *); |
| dst = va_arg(ap, u_long); |
|
| va_end(ap); |
va_end(ap); |
| |
|
| inp = sotoinpcb(so); |
flags = |
| flags = (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST; |
(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 182 rip_output(m, va_alist) |
|
| Line 184 rip_output(m, va_alist) |
|
| 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 212 rip_ctloutput(op, so, level, optname, m) |
|
| Line 214 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); |
| #ifdef MROUTING |
int error = 0; |
| int error; |
|
| #endif |
|
| |
|
| if (level != IPPROTO_IP) { |
if (level != IPPROTO_IP) { |
| if (m != 0 && *m != 0) |
error = ENOPROTOOPT; |
| (void)m_free(*m); |
if (op == PRCO_SETOPT && *m != 0) |
| return (EINVAL); |
(void) m_free(*m); |
| } |
} else switch (op) { |
| |
|
| switch (optname) { |
case PRCO_SETOPT: |
| |
switch (optname) { |
| case IP_HDRINCL: |
case IP_HDRINCL: |
| if (op == PRCO_SETOPT || op == PRCO_GETOPT) { |
if (*m == 0 || (*m)->m_len < sizeof (int)) |
| if (m == 0 || *m == 0 || (*m)->m_len < sizeof (int)) |
error = EINVAL; |
| return (EINVAL); |
else { |
| if (op == PRCO_SETOPT) { |
|
| if (*mtod(*m, int *)) |
if (*mtod(*m, int *)) |
| inp->inp_flags |= INP_HDRINCL; |
inp->inp_flags |= INP_HDRINCL; |
| else |
else |
| inp->inp_flags &= ~INP_HDRINCL; |
inp->inp_flags &= ~INP_HDRINCL; |
| (void)m_free(*m); |
|
| } else { |
|
| (*m)->m_len = sizeof (int); |
|
| *mtod(*m, int *) = inp->inp_flags & INP_HDRINCL; |
|
| } |
} |
| return (0); |
if (*m != 0) |
| |
(void) m_free(*m); |
| |
break; |
| |
|
| |
#ifdef MROUTING |
| |
case MRT_INIT: |
| |
case MRT_DONE: |
| |
case MRT_ADD_VIF: |
| |
case MRT_DEL_VIF: |
| |
case MRT_ADD_MFC: |
| |
case MRT_DEL_MFC: |
| |
case MRT_ASSERT: |
| |
error = ip_mrouter_set(so, optname, m); |
| |
break; |
| |
#endif |
| |
|
| |
default: |
| |
error = ip_ctloutput(op, so, level, optname, m); |
| |
break; |
| } |
} |
| break; |
break; |
| |
|
| case MRT_INIT: |
case PRCO_GETOPT: |
| case MRT_DONE: |
switch (optname) { |
| case MRT_ADD_VIF: |
case IP_HDRINCL: |
| case MRT_DEL_VIF: |
*m = m_get(M_WAIT, M_SOOPTS); |
| case MRT_ADD_MFC: |
(*m)->m_len = sizeof (int); |
| case MRT_DEL_MFC: |
*mtod(*m, int *) = inp->inp_flags & INP_HDRINCL ? 1 : 0; |
| case MRT_VERSION: |
|
| case MRT_ASSERT: |
|
| #ifdef MROUTING |
|
| switch (op) { |
|
| case PRCO_SETOPT: |
|
| error = ip_mrouter_set(optname, so, m); |
|
| break; |
break; |
| case PRCO_GETOPT: |
|
| error = ip_mrouter_get(optname, so, m); |
#ifdef MROUTING |
| |
case MRT_VERSION: |
| |
case MRT_ASSERT: |
| |
error = ip_mrouter_get(so, optname, m); |
| break; |
break; |
| |
#endif |
| |
|
| default: |
default: |
| error = EINVAL; |
error = ip_ctloutput(op, so, level, optname, m); |
| break; |
break; |
| } |
} |
| return (error); |
break; |
| #else |
|
| if (op == PRCO_SETOPT && *m) |
|
| m_free(*m); |
|
| return (EOPNOTSUPP); |
|
| #endif |
|
| } |
} |
| return (ip_ctloutput(op, so, level, optname, m)); |
return (error); |
| |
} |
| |
|
| |
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; |
| Line 277 u_long rip_recvspace = RIPRCVQ; |
|
| Line 331 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) |
if (req == PRU_CONTROL) |
| return (in_control(so, (long)m, (caddr_t)nam, |
return (in_control(so, (long)m, (caddr_t)nam, |
| (struct ifnet *)control)); |
(struct ifnet *)control, p)); |
| |
|
| if (inp == NULL && req != PRU_ATTACH) { |
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; |
error = EINVAL; |
| goto release; |
goto release; |
| } |
} |
| Line 299 rip_usrreq(so, req, m, nam, control) |
|
| Line 362 rip_usrreq(so, req, m, nam, control) |
|
| 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, &rawcbtable))) |
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 332 rip_usrreq(so, req, m, nam, control) |
|
| Line 391 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.tqh_first == 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.tqh_first == 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 383 rip_usrreq(so, req, m, nam, control) |
|
| Line 421 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 437 rip_usrreq(so, req, m, nam, control) |
|
| Line 488 rip_usrreq(so, req, m, nam, control) |
|
| default: |
default: |
| panic("rip_usrreq"); |
panic("rip_usrreq"); |
| } |
} |
| |
|
| release: |
release: |
| if (m != NULL) |
splx(s); |
| m_freem(m); |
|
| return (error); |
return (error); |
| } |
} |