| version 1.25.4.2, 1996/12/11 04:01:08 |
version 1.26, 1996/05/22 13:55:31 |
|
|
| |
|
| 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 109 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 != INADDR_ANY && |
if (inp->inp_laddr.s_addr && |
| 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 != INADDR_ANY && |
if (inp->inp_faddr.s_addr && |
| 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 155 rip_output(m, va_alist) |
|
| Line 151 rip_output(m, va_alist) |
|
| va_dcl |
va_dcl |
| #endif |
#endif |
| { |
{ |
| register struct inpcb *inp; |
struct socket *so; |
| |
u_long dst; |
| register struct ip *ip; |
register struct ip *ip; |
| |
register struct inpcb *inp; |
| struct mbuf *opts; |
struct mbuf *opts; |
| int flags; |
int flags; |
| va_list ap; |
va_list ap; |
| |
|
| va_start(ap, m); |
va_start(ap, m); |
| inp = va_arg(ap, struct inpcb *); |
so = va_arg(ap, struct socket *); |
| |
dst = va_arg(ap, u_long); |
| va_end(ap); |
va_end(ap); |
| |
|
| flags = |
inp = sotoinpcb(so); |
| (inp->inp_socket->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST; |
flags = (so->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. |
| * Otherwise, allocate an mbuf for a header and fill it in. |
* Otherwise, allocate an mbuf for a header and fill it in. |
| */ |
*/ |
| if ((inp->inp_flags & INP_HDRINCL) == 0) { |
if ((inp->inp_flags & INP_HDRINCL) == 0) { |
| if ((m->m_pkthdr.len + sizeof(struct ip)) > IP_MAXPACKET) { |
|
| m_freem(m); |
|
| return (EMSGSIZE); |
|
| } |
|
| M_PREPEND(m, sizeof(struct ip), M_WAIT); |
M_PREPEND(m, sizeof(struct ip), M_WAIT); |
| ip = mtod(m, struct ip *); |
ip = mtod(m, struct ip *); |
| ip->ip_tos = 0; |
ip->ip_tos = 0; |
| Line 184 rip_output(m, va_alist) |
|
| Line 179 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 = inp->inp_faddr; |
ip->ip_dst.s_addr = dst; |
| ip->ip_ttl = MAXTTL; |
ip->ip_ttl = MAXTTL; |
| opts = inp->inp_options; |
opts = inp->inp_options; |
| } else { |
} else { |
| if (m->m_pkthdr.len > IP_MAXPACKET) { |
|
| m_freem(m); |
|
| return (EMSGSIZE); |
|
| } |
|
| ip = mtod(m, struct ip *); |
ip = mtod(m, struct ip *); |
| if (ip->ip_id == 0) |
if (ip->ip_id == 0) |
| ip->ip_id = htons(ip_id++); |
ip->ip_id = htons(ip_id++); |
| Line 214 rip_ctloutput(op, so, level, optname, m) |
|
| Line 205 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); |
| int error = 0; |
#ifdef MROUTING |
| |
int error; |
| |
#endif |
| |
|
| if (level != IPPROTO_IP) { |
if (level != IPPROTO_IP) { |
| error = ENOPROTOOPT; |
if (m != 0 && *m != 0) |
| if (op == PRCO_SETOPT && *m != 0) |
(void)m_free(*m); |
| (void) m_free(*m); |
return (EINVAL); |
| } else switch (op) { |
} |
| |
|
| case PRCO_SETOPT: |
switch (optname) { |
| switch (optname) { |
|
| case IP_HDRINCL: |
case IP_HDRINCL: |
| if (*m == 0 || (*m)->m_len < sizeof (int)) |
if (op == PRCO_SETOPT || op == PRCO_GETOPT) { |
| error = EINVAL; |
if (m == 0 || *m == 0 || (*m)->m_len < sizeof (int)) |
| else { |
return (EINVAL); |
| |
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; |
| } |
} |
| if (*m != 0) |
return (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 PRCO_GETOPT: |
case MRT_INIT: |
| switch (optname) { |
case MRT_DONE: |
| case IP_HDRINCL: |
case MRT_ADD_VIF: |
| *m = m_get(M_WAIT, M_SOOPTS); |
case MRT_DEL_VIF: |
| (*m)->m_len = sizeof (int); |
case MRT_ADD_MFC: |
| *mtod(*m, int *) = inp->inp_flags & INP_HDRINCL ? 1 : 0; |
case MRT_DEL_MFC: |
| break; |
case MRT_VERSION: |
| |
case MRT_ASSERT: |
| #ifdef MROUTING |
#ifdef MROUTING |
| case MRT_VERSION: |
switch (op) { |
| case MRT_ASSERT: |
case PRCO_SETOPT: |
| error = ip_mrouter_get(so, optname, m); |
error = ip_mrouter_set(optname, so, m); |
| |
break; |
| |
case PRCO_GETOPT: |
| |
error = ip_mrouter_get(optname, so, m); |
| break; |
break; |
| #endif |
|
| |
|
| default: |
default: |
| error = ip_ctloutput(op, so, level, optname, m); |
error = EINVAL; |
| break; |
break; |
| } |
} |
| break; |
return (error); |
| |
#else |
| |
if (op == PRCO_SETOPT && *m) |
| |
m_free(*m); |
| |
return (EOPNOTSUPP); |
| |
#endif |
| } |
} |
| return (error); |
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; |
| Line 337 rip_usrreq(so, req, m, nam, control, p) |
|
| Line 276 rip_usrreq(so, req, m, nam, control, p) |
|
| struct mbuf *m, *nam, *control; |
struct mbuf *m, *nam, *control; |
| struct proc *p; |
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, p)); |
(struct ifnet *)control, p)); |
| |
|
| s = splsoftnet(); |
if (inp == NULL && req != PRU_ATTACH) { |
| 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 362 rip_usrreq(so, req, m, nam, control, p) |
|
| Line 293 rip_usrreq(so, req, m, nam, control, p) |
|
| switch (req) { |
switch (req) { |
| |
|
| case PRU_ATTACH: |
case PRU_ATTACH: |
| if (inp != 0) { |
if (inp) |
| error = EISCONN; |
panic("rip_attach"); |
| break; |
|
| } |
|
| if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag))) { |
if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag))) { |
| error = EACCES; |
error = EACCES; |
| break; |
break; |
| } |
} |
| if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { |
if ((error = soreserve(so, rip_sendspace, rip_recvspace)) || |
| error = soreserve(so, rip_sendspace, rip_recvspace); |
(error = in_pcballoc(so, &rawcbtable))) |
| if (error) |
|
| break; |
|
| } |
|
| error = in_pcballoc(so, &rawcbtable); |
|
| if (error) |
|
| break; |
break; |
| inp = sotoinpcb(so); |
inp = (struct inpcb *)so->so_pcb; |
| 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 391 rip_usrreq(so, req, m, nam, control, p) |
|
| Line 326 rip_usrreq(so, req, m, nam, control, p) |
|
| break; |
break; |
| |
|
| case PRU_BIND: |
case PRU_BIND: |
| error = rip_bind(inp, nam); |
{ |
| break; |
struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *); |
| |
|
| case PRU_LISTEN: |
if (nam->m_len != sizeof(*addr)) { |
| error = EOPNOTSUPP; |
error = EINVAL; |
| |
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: |
case PRU_CONNECT: |
| error = rip_connect(inp, nam); |
{ |
| if (error) |
struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *); |
| |
|
| |
if (nam->m_len != sizeof(*addr)) { |
| |
error = EINVAL; |
| |
break; |
| |
} |
| |
if (ifnet.tqh_first == 0) { |
| |
error = EADDRNOTAVAIL; |
| break; |
break; |
| |
} |
| |
if ((addr->sin_family != AF_INET) && |
| |
(addr->sin_family != AF_IMPLINK)) { |
| |
error = EAFNOSUPPORT; |
| |
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 421 rip_usrreq(so, req, m, nam, control, p) |
|
| Line 377 rip_usrreq(so, req, m, nam, control, p) |
|
| 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) { |
{ |
| m_freem(control); |
register u_int32_t dst; |
| m_freem(m); |
|
| error = EINVAL; |
if (so->so_state & SS_ISCONNECTED) { |
| break; |
if (nam) { |
| } |
|
| { |
|
| 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 ((so->so_state & SS_ISCONNECTED) == 0) { |
if (nam == NULL) { |
| error = ENOTCONN; |
error = ENOTCONN; |
| goto die; |
break; |
| } |
} |
| |
dst = mtod(nam, struct sockaddr_in *)->sin_addr.s_addr; |
| } |
} |
| error = rip_output(m, inp); |
error = rip_output(m, so, dst); |
| if (nam) |
m = NULL; |
| 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: |
| error = EOPNOTSUPP; |
case PRU_RCVD: |
| break; |
case PRU_LISTEN: |
| |
case PRU_ACCEPT: |
| case PRU_SENDOOB: |
case PRU_SENDOOB: |
| m_freem(control); |
|
| m_freem(m); |
|
| error = EOPNOTSUPP; |
error = EOPNOTSUPP; |
| break; |
break; |
| |
|
| Line 488 rip_usrreq(so, req, m, nam, control, p) |
|
| Line 431 rip_usrreq(so, req, m, nam, control, p) |
|
| default: |
default: |
| panic("rip_usrreq"); |
panic("rip_usrreq"); |
| } |
} |
| |
|
| release: |
release: |
| splx(s); |
if (m != NULL) |
| |
m_freem(m); |
| return (error); |
return (error); |
| } |
} |