Skip to content

Commit

Permalink
call encap6_ctlinput. XXX need testing
Browse files Browse the repository at this point in the history
  • Loading branch information
itojun committed Aug 22, 2001
1 parent 95474ba commit b082f35
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 46 deletions.
83 changes: 41 additions & 42 deletions kame/sys/netinet/ip_encap.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: ip_encap.c,v 1.62 2001/08/17 10:29:45 itojun Exp $ */
/* $KAME: ip_encap.c,v 1.63 2001/08/22 10:28:04 itojun Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -156,11 +156,15 @@ struct pack6 {
struct sockaddr_in6 yours;
} __attribute__((__packed__));

enum direction { INBOUND, OUTBOUND };

#ifdef INET
static struct encaptab *encap4_lookup __P((struct mbuf *, int, int));
static struct encaptab *encap4_lookup __P((struct mbuf *, int, int,
enum direction));
#endif
#ifdef INET6
static struct encaptab *encap6_lookup __P((struct mbuf *, int, int));
static struct encaptab *encap6_lookup __P((struct mbuf *, int, int,
enum direction));
#endif
static int encap_add __P((struct encaptab *));
static int encap_remove __P((struct encaptab *));
Expand Down Expand Up @@ -224,15 +228,14 @@ encap_init()

#ifdef INET
static struct encaptab *
encap4_lookup(m, off, proto)
encap4_lookup(m, off, proto, dir)
struct mbuf *m;
int off;
int proto;
enum direction dir;
{
struct ip *ip;
struct pack4 pack;
#define d pack.mine
#define s pack.yours
struct encaptab *ep, *match;
int prio, matchprio;
#ifdef USE_RADIX
Expand All @@ -248,12 +251,15 @@ encap4_lookup(m, off, proto)

bzero(&pack, sizeof(pack));
pack.p.sp_len = sizeof(pack);
s.sin_family = AF_INET;
s.sin_len = sizeof(struct sockaddr_in);
s.sin_addr = ip->ip_src;
d.sin_family = AF_INET;
d.sin_len = sizeof(struct sockaddr_in);
d.sin_addr = ip->ip_dst;
pack.mine.sin_family = pack.yours.sin_family = AF_INET;
pack.mine.sin_len = pack.yours.sin_len = sizeof(struct sockaddr_in);
if (dir == INBOUND) {
pack.mine.sin_addr = ip->ip_dst;
pack.yours.sin_addr = ip->ip_src;
} else {
pack.mine.sin_addr = ip->ip_src;
pack.yours.sin_addr = ip->ip_dst;
}

match = NULL;
matchprio = 0;
Expand Down Expand Up @@ -286,12 +292,8 @@ encap4_lookup(m, off, proto)
#ifdef USE_RADIX
continue;
#else
/*
* it's inbound traffic, we need to match in reverse
* order
*/
prio = mask_match(ep, (struct sockaddr *)&d,
(struct sockaddr *)&s);
prio = mask_match(ep, (struct sockaddr *)&pack.mine,
(struct sockaddr *)&pack.yours);
#endif
}

Expand Down Expand Up @@ -358,7 +360,7 @@ encap4_input(m, va_alist)
proto = ip->ip_p;
#endif

match = encap4_lookup(m, off, proto);
match = encap4_lookup(m, off, proto, INBOUND);

if (match) {
/* found a match, "match" has the best one */
Expand Down Expand Up @@ -413,15 +415,14 @@ encap4_input(m, va_alist)

#ifdef INET6
static struct encaptab *
encap6_lookup(m, off, proto)
encap6_lookup(m, off, proto, dir)
struct mbuf *m;
int off;
int proto;
enum direction dir;
{
struct ip6_hdr *ip6;
struct pack6 pack;
#define d pack.mine
#define s pack.yours
int prio, matchprio;
struct encaptab *ep, *match;
#ifdef USE_RADIX
Expand All @@ -437,12 +438,15 @@ encap6_lookup(m, off, proto)

bzero(&pack, sizeof(pack));
pack.p.sp_len = sizeof(pack);
s.sin6_family = AF_INET6;
s.sin6_len = sizeof(struct sockaddr_in6);
s.sin6_addr = ip6->ip6_src;
d.sin6_family = AF_INET6;
d.sin6_len = sizeof(struct sockaddr_in6);
d.sin6_addr = ip6->ip6_dst;
pack.mine.sin6_family = pack.yours.sin6_family = AF_INET6;
pack.mine.sin6_len = pack.yours.sin6_len = sizeof(struct sockaddr_in6);
if (dir == INBOUND) {
pack.mine.sin6_addr = ip6->ip6_dst;
pack.yours.sin6_addr = ip6->ip6_src;
} else {
pack.mine.sin6_addr = ip6->ip6_src;
pack.yours.sin6_addr = ip6->ip6_dst;
}

match = NULL;
matchprio = 0;
Expand Down Expand Up @@ -475,12 +479,8 @@ encap6_lookup(m, off, proto)
#ifdef USE_RADIX
continue;
#else
/*
* it's inbound traffic, we need to match in reverse
* order
*/
prio = mask_match(ep, (struct sockaddr *)&d,
(struct sockaddr *)&s);
prio = mask_match(ep, (struct sockaddr *)&pack.mine,
(struct sockaddr *)&pack.yours);
#endif
}

Expand Down Expand Up @@ -508,7 +508,7 @@ encap6_input(mp, offp, proto)
const struct ip6protosw *psw;
struct encaptab *match;

match = encap6_lookup(m, *offp, proto);
match = encap6_lookup(m, *offp, proto, INBOUND);

if (match) {
/* found a match */
Expand Down Expand Up @@ -816,11 +816,12 @@ encap_attach_func(af, proto, func, psw, arg)
#endif

void
encap6_ctlinput(cmd, sa, d)
encap6_ctlinput(cmd, sa, d0)
int cmd;
struct sockaddr *sa;
void *d;
void *d0;
{
void *d = d0;
struct ip6_hdr *ip6;
struct mbuf *m;
int off;
Expand Down Expand Up @@ -868,14 +869,10 @@ encap6_ctlinput(cmd, sa, d)
int valid = 0;
struct encaptab *match;

#if 0
/*
* Check to see if we have a valid encap configuration.
* XXX m is useless at this point, since it is an outbound
* traffic...
*/
match = encap6_lookup(m, off, nxt);
#endif
match = encap6_lookup(m, off, nxt, OUTBOUND);

if (match)
valid++;
Expand Down Expand Up @@ -905,6 +902,8 @@ encap6_ctlinput(cmd, sa, d)
if (psw && psw->pr_ctlinput)
(*psw->pr_ctlinput)(cmd, sa, d);
}

rip6_ctlinput(cmd, sa, d0);
}
#endif

Expand Down
8 changes: 4 additions & 4 deletions kame/sys/netinet6/in6_proto.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $KAME: in6_proto.c,v 1.104 2001/08/16 12:11:23 jinmei Exp $ */
/* $KAME: in6_proto.c,v 1.105 2001/08/22 10:28:04 itojun Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -391,7 +391,7 @@ struct ip6protosw inet6sw[] = {
#endif /* IPSEC */
#ifdef INET
{ SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
encap6_input, rip6_output, 0, rip6_ctloutput,
encap6_input, rip6_output, encap6_ctlinput, rip6_ctloutput,
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
0,
#else
Expand All @@ -404,7 +404,7 @@ struct ip6protosw inet6sw[] = {
},
#endif /* INET */
{ SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
encap6_input, rip6_output, 0, rip6_ctloutput,
encap6_input, rip6_output, encap6_ctlinput, rip6_ctloutput,
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
0,
#else
Expand All @@ -417,7 +417,7 @@ struct ip6protosw inet6sw[] = {
},
#if defined(__NetBSD__) && defined(ISO)
{ SOCK_RAW, &inet6domain, IPPROTO_EON, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
encap6_input, rip6_output, 0, rip6_ctloutput,
encap6_input, rip6_output, encap6_ctlinput, rip6_ctloutput,
rip6_usrreq, /* XXX */
encap_init, 0, 0, 0,
},
Expand Down

0 comments on commit b082f35

Please sign in to comment.