#include <netinet6/scope6_var.h>
#endif
#include <netinet6/raw_ip6.h>
+#include <netinet6/ip6_fw.h>
#if IPSEC
#include <netinet6/ipsec.h>
#include <netinet6/ipsec6.h>
extern int ipsec_bypass;
+extern lck_mtx_t *sadb_mutex;
#endif /*IPSEC*/
extern struct inpcbinfo ripcbinfo;
extern u_long rip_sendspace;
extern u_long rip_recvspace;
+extern u_long route_generation;
struct rip6stat rip6stat;
* mbuf chain.
*/
int
-rip6_input(mp, offp)
- struct mbuf **mp;
- int *offp;
+rip6_input(
+ struct mbuf **mp,
+ int *offp)
{
struct mbuf *m = *mp;
register struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
init_sin6(&rip6src, m); /* general init */
+ lck_rw_lock_shared(ripcbinfo.mtx);
LIST_FOREACH(in6p, &ripcb, inp_list) {
if ((in6p->in6p_vflag & INP_IPV6) == 0)
continue;
/*
* Check AH/ESP integrity.
*/
- if (ipsec_bypass == 0 && n && ipsec6_in_reject_so(n, last->inp_socket)) {
- m_freem(n);
- ipsec6stat.in_polvio++;
- /* do not inject data into pcb */
+ if (ipsec_bypass == 0 && n) {
+ lck_mtx_lock(sadb_mutex);
+ if (ipsec6_in_reject_so(n, last->inp_socket)) {
+ m_freem(n);
+ ipsec6stat.in_polvio++;
+ /* do not inject data into pcb */
+ }
+ lck_mtx_unlock(sadb_mutex);
} else
#endif /*IPSEC*/
if (n) {
m_adj(n, *offp);
if (sbappendaddr(&last->in6p_socket->so_rcv,
(struct sockaddr *)&rip6src,
- n, opts) == 0) {
- m_freem(n);
- if (opts)
- m_freem(opts);
+ n, opts, NULL) == 0) {
rip6stat.rip6s_fullsock++;
} else
sorwakeup(last->in6p_socket);
}
last = in6p;
}
+ lck_rw_done(ripcbinfo.mtx);
#if IPSEC
/*
* Check AH/ESP integrity.
*/
- if (ipsec_bypass == 0 && last && ipsec6_in_reject_so(m, last->inp_socket)) {
- m_freem(m);
- ipsec6stat.in_polvio++;
- ip6stat.ip6s_delivered--;
- /* do not inject data into pcb */
+ if (ipsec_bypass == 0 && last) {
+ lck_mtx_lock(sadb_mutex);
+ if (ipsec6_in_reject_so(m, last->inp_socket)) {
+ m_freem(m);
+ ipsec6stat.in_polvio++;
+ ip6stat.ip6s_delivered--;
+ /* do not inject data into pcb */
+ }
+ lck_mtx_unlock(sadb_mutex);
} else
#endif /*IPSEC*/
if (last) {
/* strip intermediate headers */
m_adj(m, *offp);
if (sbappendaddr(&last->in6p_socket->so_rcv,
- (struct sockaddr *)&rip6src, m, opts) == 0) {
- m_freem(m);
- if (opts)
- m_freem(opts);
+ (struct sockaddr *)&rip6src, m, opts, NULL) == 0) {
rip6stat.rip6s_fullsock++;
} else
sorwakeup(last->in6p_socket);
}
void
-rip6_ctlinput(cmd, sa, d)
- int cmd;
- struct sockaddr *sa;
- void *d;
+rip6_ctlinput(
+ int cmd,
+ struct sockaddr *sa,
+ void *d)
{
struct ip6_hdr *ip6;
struct mbuf *m;
int off = 0;
struct ip6ctlparam *ip6cp = NULL;
const struct sockaddr_in6 *sa6_src = NULL;
- void (*notify) __P((struct inpcb *, int)) = in6_rtchange;
+ void (*notify)(struct inpcb *, int) = in6_rtchange;
if (sa->sa_family != AF_INET6 ||
sa->sa_len != sizeof(struct sockaddr_in6))
sa6_src = &sa6_any;
}
- (void) in6_pcbnotify(&ripcb, sa, 0, (struct sockaddr *)sa6_src,
+ (void) in6_pcbnotify(&ripcbinfo, sa, 0, (struct sockaddr *)sa6_src,
0, cmd, notify);
}
* Tack on options user may have setup with control call.
*/
int
-rip6_output(m, so, dstsock, control)
- register struct mbuf *m;
- struct socket *so;
- struct sockaddr_in6 *dstsock;
- struct mbuf *control;
+rip6_output(
+ register struct mbuf *m,
+ struct socket *so,
+ struct sockaddr_in6 *dstsock,
+ struct mbuf *control)
{
struct in6_addr *dst;
struct ip6_hdr *ip6;
*/
{
struct in6_addr *in6a;
+ struct in6_addr storage;
if ((in6a = in6_selectsrc(dstsock, optp,
in6p->in6p_moptions,
&in6p->in6p_route,
&in6p->in6p_laddr,
- &error)) == 0) {
+ &storage, &error)) == 0) {
if (error == 0)
error = EADDRNOTAVAIL;
goto bad;
}
#endif /*IPSEC*/
+ if (in6p->in6p_route.ro_rt && in6p->in6p_route.ro_rt->generation_id != route_generation) {
+ rtfree(in6p->in6p_route.ro_rt);
+ in6p->in6p_route.ro_rt = (struct rtentry *)0;
+ }
+
error = ip6_output(m, optp, &in6p->in6p_route, 0,
- in6p->in6p_moptions, &oifp);
+ in6p->in6p_moptions, &oifp, 0);
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) {
if (oifp)
icmp6_ifoutstat_inc(oifp, type, code);
return(error);
}
+static void
+load_ip6fw()
+{
+ ip6_fw_init();
+}
+
/*
* Raw IPv6 socket option processing.
*/
int
-rip6_ctloutput(so, sopt)
- struct socket *so;
- struct sockopt *sopt;
+rip6_ctloutput(
+ struct socket *so,
+ struct sockopt *sopt)
{
int error;
switch (sopt->sopt_dir) {
case SOPT_GET:
switch (sopt->sopt_name) {
+ case IPV6_FW_ADD:
+ case IPV6_FW_GET:
+ if (ip6_fw_ctl_ptr == 0)
+ load_ip6fw();
+ if (ip6_fw_ctl_ptr)
+ error = ip6_fw_ctl_ptr(sopt);
+ else
+ error = ENOPROTOOPT;
+ break;
+
case MRT6_INIT:
case MRT6_DONE:
case MRT6_ADD_MIF:
case SOPT_SET:
switch (sopt->sopt_name) {
+ case IPV6_FW_ADD:
+ case IPV6_FW_DEL:
+ case IPV6_FW_FLUSH:
+ case IPV6_FW_ZERO:
+ if (ip6_fw_ctl_ptr == 0)
+ load_ip6fw();
+ if (ip6_fw_ctl_ptr)
+ error = ip6_fw_ctl_ptr(sopt);
+ else
+ error = ENOPROTOOPT;
+ break;
+
case MRT6_INIT:
case MRT6_DONE:
case MRT6_ADD_MIF:
inp = sotoinpcb(so);
if (inp)
panic("rip6_attach");
- if (p && (error = suser(p->p_ucred, &p->p_acflag)) != 0)
+ if (p && (error = proc_suser(p)) != 0)
return error;
error = soreserve(so, rip_sendspace, rip_recvspace);
inp->in6p_hops = -1; /* use kernel default */
inp->in6p_cksum = -1;
MALLOC(inp->in6p_icmp6filt, struct icmp6_filter *,
- sizeof(struct icmp6_filter), M_PCB, M_NOWAIT);
+ sizeof(struct icmp6_filter), M_PCB, M_WAITOK);
+ if (inp->in6p_icmp6filt == NULL)
+ return (ENOMEM);
ICMP6_FILTER_SETPASSALL(inp->in6p_icmp6filt);
return 0;
}
if (nam->sa_len != sizeof(*addr))
return EINVAL;
- if (TAILQ_EMPTY(&ifnet) || addr->sin6_family != AF_INET6)
+ if (TAILQ_EMPTY(&ifnet_head) || addr->sin6_family != AF_INET6)
return EADDRNOTAVAIL;
#if ENABLE_DEFAULT_SCOPE
if (addr->sin6_scope_id == 0) { /* not change if specified */
((struct in6_ifaddr *)ia)->ia6_flags &
(IN6_IFF_ANYCAST|IN6_IFF_NOTREADY|
IN6_IFF_DETACHED|IN6_IFF_DEPRECATED)) {
+ if (ia) ifafree(ia);
return(EADDRNOTAVAIL);
}
+ ifafree(ia);
inp->in6p_laddr = addr->sin6_addr;
return 0;
}
struct inpcb *inp = sotoinpcb(so);
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam;
struct in6_addr *in6a = NULL;
+ struct in6_addr storage;
int error = 0;
#if ENABLE_DEFAULT_SCOPE
struct sockaddr_in6 tmp;
if (nam->sa_len != sizeof(*addr))
return EINVAL;
- if (TAILQ_EMPTY(&ifnet))
+ if (TAILQ_EMPTY(&ifnet_head))
return EADDRNOTAVAIL;
if (addr->sin6_family != AF_INET6)
return EAFNOSUPPORT;
/* Source address selection. XXX: need pcblookup? */
in6a = in6_selectsrc(addr, inp->in6p_outputopts,
inp->in6p_moptions, &inp->in6p_route,
- &inp->in6p_laddr, &error);
+ &inp->in6p_laddr, &storage, &error);
if (in6a == NULL)
return (error ? error : EADDRNOTAVAIL);
inp->in6p_laddr = *in6a;
pru_connect2_notsupp, in6_control, rip6_detach, rip6_disconnect,
pru_listen_notsupp, in6_setpeeraddr, pru_rcvd_notsupp,
pru_rcvoob_notsupp, rip6_send, pru_sense_null, rip6_shutdown,
- in6_setsockaddr, sosend, soreceive, sopoll
+ in6_setsockaddr, sosend, soreceive, pru_sopoll_notsupp
};