version 1.25, 1996/02/18 18:58:33 |
version 1.27, 1996/05/23 16:12:15 |
|
|
#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> |
Line 104 rip_input(m, va_alist) |
|
Line 105 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 151 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 178 rip_output(m, va_alist) |
|
Line 176 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 264 rip_ctloutput(op, so, level, optname, m) |
|
Line 262 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_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) |
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); |
|
if (control && control->m_len) { |
|
m_freem(control); |
|
error = EINVAL; |
|
goto release; |
|
} |
|
if (inp == 0 && req != PRU_ATTACH) { |
error = EINVAL; |
error = EINVAL; |
goto release; |
goto release; |
} |
} |
Line 291 rip_usrreq(so, req, m, nam, control) |
|
Line 325 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 331 rip_usrreq(so, req, m, nam, control) |
|
Line 361 rip_usrreq(so, req, m, nam, control) |
|
error = EINVAL; |
error = EINVAL; |
break; |
break; |
} |
} |
if ((ifnet.tqh_first == 0) || |
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; |
error = EADDRNOTAVAIL; |
break; |
break; |
} |
} |
inp->inp_laddr = addr->sin_addr; |
if (addr->sin_family != AF_INET && |
break; |
addr->sin_family != AF_IMPLINK) { |
} |
error = EAFNOSUPPORT; |
case PRU_CONNECT: |
|
{ |
|
struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *); |
|
|
|
if (nam->m_len != sizeof(*addr)) { |
|
error = EINVAL; |
|
break; |
break; |
} |
} |
if (ifnet.tqh_first == 0) { |
if (addr->sin_addr.s_addr != INADDR_ANY && |
|
ifa_ifwithaddr(sintosa(addr)) == 0) { |
error = EADDRNOTAVAIL; |
error = EADDRNOTAVAIL; |
break; |
break; |
} |
} |
if ((addr->sin_family != AF_INET) && |
inp->inp_laddr = addr->sin_addr; |
(addr->sin_family != AF_IMPLINK)) { |
break; |
error = EAFNOSUPPORT; |
} |
|
|
|
case PRU_LISTEN: |
|
error = EOPNOTSUPP; |
|
break; |
|
|
|
case PRU_CONNECT: |
|
error = rip_connect(inp, nam); |
|
if (error) |
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 375 rip_usrreq(so, req, m, nam, control) |
|
Line 406 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: |
{ |
{ |
register u_int32_t dst; |
struct in_addr faddr; |
|
|
if (so->so_state & SS_ISCONNECTED) { |
if (nam) { |
if (nam) { |
if ((so->so_state & SS_ISCONNECTED) != 0) { |
|
m_freem(m); |
error = EISCONN; |
error = EISCONN; |
break; |
break; |
} |
} |
dst = inp->inp_faddr.s_addr; |
error = rip_connect(inp, nam); |
|
if (error) { |
|
m_freem(m); |
|
break; |
|
} |
} else { |
} else { |
if (nam == NULL) { |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
|
m_freem(m); |
error = ENOTCONN; |
error = ENOTCONN; |
break; |
break; |
} |
} |
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; |
} |
} |
|
|
Line 405 rip_usrreq(so, req, m, nam, control) |
|
Line 446 rip_usrreq(so, req, m, nam, control) |
|
/* |
/* |
* 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(m); |
error = EOPNOTSUPP; |
error = EOPNOTSUPP; |
break; |
break; |
|
|
Line 429 rip_usrreq(so, req, m, nam, control) |
|
Line 469 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); |
} |
} |