version 1.21.2.1, 2000/06/22 17:10:01 |
version 1.30, 2000/12/14 17:36:45 |
|
|
/* $NetBSD$ */ |
/* $NetBSD$ */ |
/* $KAME: ip6_input.c,v 1.94 2000/06/13 10:06:19 jinmei Exp $ */ |
/* $KAME: ip6_input.c,v 1.121 2000/08/31 06:07:29 itojun Exp $ */ |
|
|
/* |
/* |
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
Line 140 ip6_fw_chk_t *ip6_fw_chk_ptr; |
|
Line 140 ip6_fw_chk_t *ip6_fw_chk_ptr; |
|
ip6_fw_ctl_t *ip6_fw_ctl_ptr; |
ip6_fw_ctl_t *ip6_fw_ctl_ptr; |
#endif |
#endif |
|
|
|
#ifdef PFIL_HOOKS |
|
struct pfil_head inet6_pfil_hook; |
|
#endif |
|
|
struct ip6stat ip6stat; |
struct ip6stat ip6stat; |
|
|
static void ip6_init2 __P((void *)); |
static void ip6_init2 __P((void *)); |
|
|
ip6_flow_seq = random() ^ tv.tv_usec; |
ip6_flow_seq = random() ^ tv.tv_usec; |
|
|
ip6_init2((void *)0); |
ip6_init2((void *)0); |
|
|
|
#ifdef PFIL_HOOKS |
|
/* Register our Packet Filter hook. */ |
|
inet6_pfil_hook.ph_key = (void *)(u_long) AF_INET6; |
|
inet6_pfil_hook.ph_dlt = DLT_RAW; |
|
i = pfil_head_register(&inet6_pfil_hook); |
|
if (i != 0) |
|
printf("ip6_init: WARNING: unable to register pfil hook, " |
|
"error %d\n", i); |
|
#endif /* PFIL_HOOKS */ |
} |
} |
|
|
static void |
static void |
|
|
u_int32_t rtalert = ~0; |
u_int32_t rtalert = ~0; |
int nxt, ours = 0; |
int nxt, ours = 0; |
struct ifnet *deliverifp = NULL; |
struct ifnet *deliverifp = NULL; |
#ifdef PFIL_HOOKS |
|
struct packet_filter_hook *pfh; |
|
struct mbuf *m0; |
|
int rv; |
|
#endif /* PFIL_HOOKS */ |
|
|
|
#ifdef IPSEC |
#ifdef IPSEC |
/* |
/* |
|
|
* Note that filters must _never_ set this flag, as another filter |
* Note that filters must _never_ set this flag, as another filter |
* in the list may have previously cleared it. |
* in the list may have previously cleared it. |
*/ |
*/ |
m0 = m; |
if (pfil_run_hooks(&inet6_pfil_hook, &m, m->m_pkthdr.rcvif, |
pfh = pfil_hook_get(PFIL_IN, &inetsw[ip_protox[IPPROTO_IPV6]].pr_pfh); |
PFIL_IN) != 0) |
for (; pfh; pfh = pfh->pfil_link.tqe_next) |
return; |
if (pfh->pfil_func) { |
if (m == NULL) |
rv = pfh->pfil_func(ip6, sizeof(*ip6), |
return; |
m->m_pkthdr.rcvif, 0, &m0); |
ip6 = mtod(m, struct ip6_hdr *); |
if (rv) |
|
return; |
|
m = m0; |
|
if (m == NULL) |
|
return; |
|
ip6 = mtod(m, struct ip6_hdr *); |
|
} |
|
#endif /* PFIL_HOOKS */ |
#endif /* PFIL_HOOKS */ |
|
|
|
|
|
|
} |
} |
#endif |
#endif |
|
|
|
#ifdef ALTQ |
|
/* XXX Temporary until ALTQ is changed to use a pfil hook */ |
|
if (altq_input != NULL && (*altq_input)(m, AF_INET6) == 0) { |
|
/* packet is dropped by traffic conditioner */ |
|
return; |
|
} |
|
#endif |
|
|
/* |
/* |
* Scope check |
* Scope check |
*/ |
*/ |
|
|
(ip6_forward_rt.ro_rt->rt_flags & RTF_UP) != 0 && |
(ip6_forward_rt.ro_rt->rt_flags & RTF_UP) != 0 && |
IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, |
IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, |
&ip6_forward_rt.ro_dst.sin6_addr)) |
&ip6_forward_rt.ro_dst.sin6_addr)) |
; /* cache hit */ |
ip6stat.ip6s_forward_cachehit++; |
else { |
else { |
if (ip6_forward_rt.ro_rt) { |
if (ip6_forward_rt.ro_rt) { |
/* route is down or destination is different */ |
/* route is down or destination is different */ |
|
ip6stat.ip6s_forward_cachemiss++; |
RTFREE(ip6_forward_rt.ro_rt); |
RTFREE(ip6_forward_rt.ro_rt); |
ip6_forward_rt.ro_rt = 0; |
ip6_forward_rt.ro_rt = 0; |
} |
} |
|
|
ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_LOOP) { |
ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_LOOP) { |
struct in6_ifaddr *ia6 = |
struct in6_ifaddr *ia6 = |
(struct in6_ifaddr *)ip6_forward_rt.ro_rt->rt_ifa; |
(struct in6_ifaddr *)ip6_forward_rt.ro_rt->rt_ifa; |
/* packet to tentative address must not be received */ |
|
if (ia6->ia6_flags & IN6_IFF_ANYCAST) |
if (ia6->ia6_flags & IN6_IFF_ANYCAST) |
m->m_flags |= M_ANYCAST6; |
m->m_flags |= M_ANYCAST6; |
|
/* |
|
* packets to a tentative, duplicated, or somehow invalid |
|
* address must not be accepted. |
|
*/ |
if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) { |
if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) { |
/* this interface is ready */ |
/* this address is ready */ |
ours = 1; |
ours = 1; |
deliverifp = ia6->ia_ifp; /* correct? */ |
deliverifp = ia6->ia_ifp; /* correct? */ |
goto hbhcheck; |
goto hbhcheck; |
} else { |
} else { |
/* this interface is not ready, fall through */ |
/* address is not ready, so discard the packet. */ |
|
log(LOG_INFO, |
|
"ip6_input: packet to an unready address %s->%s\n", |
|
ip6_sprintf(&ip6->ip6_src), |
|
ip6_sprintf(&ip6->ip6_dst)); |
|
|
|
goto bad; |
} |
} |
} |
} |
|
|
|
|
return; |
return; |
} |
} |
|
|
|
ip6 = mtod(m, struct ip6_hdr *); |
|
|
|
/* |
|
* Malicious party may be able to use IPv4 mapped addr to confuse |
|
* tcp/udp stack and bypass security checks (act as if it was from |
|
* 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1). Be cautious. |
|
* |
|
* For SIIT end node behavior, you may want to disable the check. |
|
* However, you will become vulnerable to attacks using IPv4 mapped |
|
* source. |
|
*/ |
|
if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) || |
|
IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { |
|
ip6stat.ip6s_badscope++; |
|
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); |
|
goto bad; |
|
} |
|
|
/* |
/* |
* Tell launch routine the next header |
* Tell launch routine the next header |
*/ |
*/ |
#ifdef IFA_STATS |
#ifdef IFA_STATS |
if (IFA_STATS && deliverifp != NULL) { |
if (deliverifp != NULL) { |
struct in6_ifaddr *ia6; |
struct in6_ifaddr *ia6; |
ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst); |
ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst); |
if (ia6) |
if (ia6) |
Line 800 ip6_process_hopopts(m, opthead, hbhlen, |
|
Line 838 ip6_process_hopopts(m, opthead, hbhlen, |
|
if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) |
if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) |
/* XXX: should we discard the packet? */ |
/* XXX: should we discard the packet? */ |
log(LOG_ERR, "length of jumbopayload opt " |
log(LOG_ERR, "length of jumbopayload opt " |
"is inconsistent(%d)", |
"is inconsistent(%d)\n", |
*(opt + 1)); |
*(opt + 1)); |
optlen = IP6OPT_JUMBO_LEN; |
optlen = IP6OPT_JUMBO_LEN; |
|
|
Line 1325 u_char inet6ctlerrmap[PRC_NCMDS] = { |
|
Line 1363 u_char inet6ctlerrmap[PRC_NCMDS] = { |
|
ENOPROTOOPT |
ENOPROTOOPT |
}; |
}; |
|
|
#include <vm/vm.h> |
#include <uvm/uvm_extern.h> |
#include <sys/sysctl.h> |
#include <sys/sysctl.h> |
|
|
int |
int |
Line 1337 ip6_sysctl(name, namelen, oldp, oldlenp, |
|
Line 1375 ip6_sysctl(name, namelen, oldp, oldlenp, |
|
void *newp; |
void *newp; |
size_t newlen; |
size_t newlen; |
{ |
{ |
|
int old, error; |
|
|
/* All sysctl names at this level are terminal. */ |
/* All sysctl names at this level are terminal. */ |
if (namelen != 1) |
if (namelen != 1) |
return ENOTDIR; |
return ENOTDIR; |
Line 1388 ip6_sysctl(name, namelen, oldp, oldlenp, |
|
Line 1428 ip6_sysctl(name, namelen, oldp, oldlenp, |
|
return sysctl_int(oldp, oldlenp, newp, newlen, |
return sysctl_int(oldp, oldlenp, newp, newlen, |
&ip6_bindv6only); |
&ip6_bindv6only); |
#endif |
#endif |
|
case IPV6CTL_ANONPORTMIN: |
|
old = ip6_anonportmin; |
|
error = sysctl_int(oldp, oldlenp, newp, newlen, |
|
&ip6_anonportmin); |
|
if (ip6_anonportmin >= ip6_anonportmax || ip6_anonportmin < 0 || |
|
ip6_anonportmin > 65535 |
|
#ifndef IPNOPRIVPORTS |
|
|| ip6_anonportmin < IPV6PORT_RESERVED |
|
#endif |
|
) { |
|
ip6_anonportmin = old; |
|
return (EINVAL); |
|
} |
|
return (error); |
|
case IPV6CTL_ANONPORTMAX: |
|
old = ip6_anonportmax; |
|
error = sysctl_int(oldp, oldlenp, newp, newlen, |
|
&ip6_anonportmax); |
|
if (ip6_anonportmin >= ip6_anonportmax || ip6_anonportmax < 0 || |
|
ip6_anonportmax > 65535 |
|
#ifndef IPNOPRIVPORTS |
|
|| ip6_anonportmax < IPV6PORT_RESERVED |
|
#endif |
|
) { |
|
ip6_anonportmax = old; |
|
return (EINVAL); |
|
} |
|
return (error); |
|
#ifndef IPNOPRIVPORTS |
|
case IPV6CTL_LOWPORTMIN: |
|
old = ip6_lowportmin; |
|
error = sysctl_int(oldp, oldlenp, newp, newlen, |
|
&ip6_lowportmin); |
|
if (ip6_lowportmin >= ip6_lowportmax || |
|
ip6_lowportmin > IPV6PORT_RESERVEDMAX || |
|
ip6_lowportmin < IPV6PORT_RESERVEDMIN) { |
|
ip6_lowportmin = old; |
|
return (EINVAL); |
|
} |
|
return (error); |
|
case IPV6CTL_LOWPORTMAX: |
|
old = ip6_lowportmax; |
|
error = sysctl_int(oldp, oldlenp, newp, newlen, |
|
&ip6_lowportmax); |
|
if (ip6_lowportmin >= ip6_lowportmax || |
|
ip6_lowportmax > IPV6PORT_RESERVEDMAX || |
|
ip6_lowportmax < IPV6PORT_RESERVEDMIN) { |
|
ip6_lowportmax = old; |
|
return (EINVAL); |
|
} |
|
return (error); |
|
#endif |
default: |
default: |
return EOPNOTSUPP; |
return EOPNOTSUPP; |
} |
} |