Fix build for NOINET and NOINET6 kernels.

Use own protosw structures for both address families.
Check proto in encapcheck function and use -1 as proto argument in
encap_attach_func(), both address families can have IPPROTO_IPV4
and IPPROTO_IPV6 protocols.

Reported by:	bz
This commit is contained in:
Andrey V. Elsukov 2016-04-24 17:09:51 +00:00
parent 77eab110a9
commit 0d05666462
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=298549

View File

@ -50,7 +50,6 @@
#include <netinet/ip_encap.h>
#include <net/netisr.h>
#include <net/route.h>
#include <net/vnet.h>
#include <netipsec/ipsec.h>
@ -58,6 +57,7 @@
#ifdef INET6
#include <netinet/ip6.h>
#include <netinet6/ip6_var.h>
#include <netipsec/ipsec6.h>
#endif
@ -65,7 +65,6 @@
#include <netipsec/ipcomp_var.h>
#include <netipsec/key.h>
#include <netipsec/key_debug.h>
#include <opencrypto/cryptodev.h>
#include <opencrypto/deflate.h>
@ -101,7 +100,6 @@ ipcomp_algorithm_lookup(int alg)
return NULL;
}
#if defined(INET) || defined(INET6)
/*
* RFC 3173 p 2.2. Non-Expansion Policy:
* If the total size of a compressed payload and the IPComp header, as
@ -157,19 +155,6 @@ ipcomp_nonexp_input(struct mbuf **mp, int *offp, int proto)
return (IPPROTO_DONE);
}
extern struct domain inetdomain;
static struct protosw ipcomp_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = 0 /* IPPROTO_IPV[46] */,
.pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
.pr_input = ipcomp_nonexp_input,
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs
};
#endif /* INET || INET6 */
/*
* ipcomp_init() is called when an CPI is being set up.
*/
@ -702,6 +687,18 @@ static struct xformsw ipcomp_xformsw = {
#ifdef INET
static const struct encaptab *ipe4_cookie = NULL;
extern struct domain inetdomain;
static struct protosw ipcomp4_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = 0 /* IPPROTO_IPV[46] */,
.pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
.pr_input = ipcomp_nonexp_input,
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs
};
static int
ipcomp4_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
void *arg __unused)
@ -711,6 +708,8 @@ ipcomp4_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
if (V_ipcomp_enable == 0)
return (0);
if (proto != IPPROTO_IPV4 && proto != IPPROTO_IPV6)
return (0);
bzero(&src, sizeof(src));
bzero(&dst, sizeof(dst));
src.sa.sa_family = dst.sa.sa_family = AF_INET;
@ -723,6 +722,18 @@ ipcomp4_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
#endif
#ifdef INET6
static const struct encaptab *ipe6_cookie = NULL;
extern struct domain inet6domain;
static struct protosw ipcomp6_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = 0 /* IPPROTO_IPV[46] */,
.pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
.pr_input = ipcomp_nonexp_input,
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreqs = &rip6_usrreqs
};
static int
ipcomp6_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
void *arg __unused)
@ -732,6 +743,8 @@ ipcomp6_nonexp_encapcheck(const struct mbuf *m, int off, int proto,
if (V_ipcomp_enable == 0)
return (0);
if (proto != IPPROTO_IPV4 && proto != IPPROTO_IPV6)
return (0);
bzero(&src, sizeof(src));
bzero(&dst, sizeof(dst));
src.sa.sa_family = dst.sa.sa_family = AF_INET;
@ -760,12 +773,12 @@ ipcomp_attach(void)
{
#ifdef INET
ipe4_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4,
ipcomp4_nonexp_encapcheck, &ipcomp_protosw, NULL);
ipe4_cookie = encap_attach_func(AF_INET, -1,
ipcomp4_nonexp_encapcheck, &ipcomp4_protosw, NULL);
#endif
#ifdef INET6
ipe6_cookie = encap_attach_func(AF_INET6, IPPROTO_IPV6,
ipcomp6_nonexp_encapcheck, &ipcomp_protosw, NULL);
ipe6_cookie = encap_attach_func(AF_INET6, -1,
ipcomp6_nonexp_encapcheck, &ipcomp6_protosw, NULL);
#endif
xform_register(&ipcomp_xformsw);
}