svn commit: r310525 - projects/ipsec/sys/netipsec
Andrey V. Elsukov
ae at FreeBSD.org
Sat Dec 24 20:02:30 UTC 2016
Author: ae
Date: Sat Dec 24 20:02:28 2016
New Revision: 310525
URL: https://svnweb.freebsd.org/changeset/base/310525
Log:
Move ipsec[46]_setsockaddrs() into subr_ipsec.c. These functions are needed
for both ipsec.ko and tcpmd5.ko.
Modified:
projects/ipsec/sys/netipsec/ipsec.c
projects/ipsec/sys/netipsec/ipsec.h
projects/ipsec/sys/netipsec/ipsec6.h
projects/ipsec/sys/netipsec/subr_ipsec.c
Modified: projects/ipsec/sys/netipsec/ipsec.c
==============================================================================
--- projects/ipsec/sys/netipsec/ipsec.c Sat Dec 24 17:42:34 2016 (r310524)
+++ projects/ipsec/sys/netipsec/ipsec.c Sat Dec 24 20:02:28 2016 (r310525)
@@ -260,14 +260,10 @@ static void ipsec_setspidx_inpcb(struct
u_int);
static void ipsec4_get_ulp(const struct mbuf *, struct secpolicyindex *, int);
-static void ipsec4_setsockaddrs(const struct mbuf *, union sockaddr_union *,
- union sockaddr_union *);
static void ipsec4_setspidx_ipaddr(const struct mbuf *,
struct secpolicyindex *);
#ifdef INET6
static void ipsec6_get_ulp(const struct mbuf *m, struct secpolicyindex *, int);
-static void ipsec6_setsockaddrs(const struct mbuf *, union sockaddr_union *,
- union sockaddr_union *);
static void ipsec6_setspidx_ipaddr(const struct mbuf *,
struct secpolicyindex *);
#endif
@@ -475,61 +471,8 @@ ipsec_setspidx_inpcb(struct inpcb *inp,
printf("%s: ", __func__); kdebug_secpolicyindex(spidx, NULL));
}
-void
-ipsec_setsockaddrs(const struct mbuf *m, union sockaddr_union *src,
- union sockaddr_union *dst)
-{
- struct ip *ip;
-
- IPSEC_ASSERT(m->m_len >= sizeof(*ip), ("unexpected mbuf len"));
-
- ip = mtod(m, struct ip *);
- switch (ip->ip_v) {
-#ifdef INET
- case IPVERSION:
- ipsec4_setsockaddrs(m, src, dst);
- break;
-#endif
-#ifdef INET6
- case (IPV6_VERSION >> 4):
- ipsec6_setsockaddrs(m, src, dst);
- break;
-#endif
- default:
- bzero(src, sizeof(*src));
- bzero(dst, sizeof(*dst));
- }
-}
-
#ifdef INET
static void
-ipsec4_setsockaddrs(const struct mbuf *m, union sockaddr_union *src,
- union sockaddr_union *dst)
-{
- static const struct sockaddr_in template = {
- sizeof (struct sockaddr_in),
- AF_INET,
- 0, { 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }
- };
-
- src->sin = template;
- dst->sin = template;
-
- if (m->m_len < sizeof (struct ip)) {
- m_copydata(m, offsetof(struct ip, ip_src),
- sizeof (struct in_addr),
- (caddr_t) &src->sin.sin_addr);
- m_copydata(m, offsetof(struct ip, ip_dst),
- sizeof (struct in_addr),
- (caddr_t) &dst->sin.sin_addr);
- } else {
- const struct ip *ip = mtod(m, const struct ip *);
- src->sin.sin_addr = ip->ip_src;
- dst->sin.sin_addr = ip->ip_dst;
- }
-}
-
-static void
ipsec4_get_ulp(const struct mbuf *m, struct secpolicyindex *spidx,
int needport)
{
@@ -715,39 +658,6 @@ ipsec4_capability(struct mbuf *m, u_int
#ifdef INET6
static void
-ipsec6_setsockaddrs(const struct mbuf *m, union sockaddr_union *src,
- union sockaddr_union *dst)
-{
- struct ip6_hdr ip6buf;
- const struct ip6_hdr *ip6;
-
- if (m->m_len >= sizeof(*ip6))
- ip6 = mtod(m, const struct ip6_hdr *);
- else {
- m_copydata(m, 0, sizeof(ip6buf), (caddr_t)&ip6buf);
- ip6 = &ip6buf;
- }
-
- bzero(&src->sin6, sizeof(struct sockaddr_in6));
- src->sin6.sin6_family = AF_INET6;
- src->sin6.sin6_len = sizeof(struct sockaddr_in6);
- bcopy(&ip6->ip6_src, &src->sin6.sin6_addr, sizeof(ip6->ip6_src));
- if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src)) {
- src->sin6.sin6_addr.s6_addr16[1] = 0;
- src->sin6.sin6_scope_id = ntohs(ip6->ip6_src.s6_addr16[1]);
- }
-
- bzero(&dst->sin6, sizeof(struct sockaddr_in6));
- dst->sin6.sin6_family = AF_INET6;
- dst->sin6.sin6_len = sizeof(struct sockaddr_in6);
- bcopy(&ip6->ip6_dst, &dst->sin6.sin6_addr, sizeof(ip6->ip6_dst));
- if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst)) {
- dst->sin6.sin6_addr.s6_addr16[1] = 0;
- dst->sin6.sin6_scope_id = ntohs(ip6->ip6_dst.s6_addr16[1]);
- }
-}
-
-static void
ipsec6_get_ulp(const struct mbuf *m, struct secpolicyindex *spidx,
int needport)
{
Modified: projects/ipsec/sys/netipsec/ipsec.h
==============================================================================
--- projects/ipsec/sys/netipsec/ipsec.h Sat Dec 24 17:42:34 2016 (r310524)
+++ projects/ipsec/sys/netipsec/ipsec.h Sat Dec 24 20:02:28 2016 (r310525)
@@ -318,9 +318,8 @@ int ipsec_chkreplay(uint32_t, struct sec
int ipsec_updatereplay(uint32_t, struct secasvar *);
int ipsec_updateid(struct secasvar *, uint64_t *, uint64_t *);
-void ipsec_setsockaddrs(const struct mbuf *, union sockaddr_union *,
+void ipsec4_setsockaddrs(const struct mbuf *, union sockaddr_union *,
union sockaddr_union *);
-
int ipsec4_in_reject(const struct mbuf *, struct inpcb *);
int ipsec4_input(struct mbuf *, int, int);
int ipsec4_forward(struct mbuf *);
Modified: projects/ipsec/sys/netipsec/ipsec6.h
==============================================================================
--- projects/ipsec/sys/netipsec/ipsec6.h Sat Dec 24 17:42:34 2016 (r310524)
+++ projects/ipsec/sys/netipsec/ipsec6.h Sat Dec 24 20:02:28 2016 (r310525)
@@ -62,6 +62,8 @@ struct inpcb;
struct secpolicy *ipsec6_checkpolicy(const struct mbuf *,
struct inpcb *, int *);
+void ipsec6_setsockaddrs(const struct mbuf *, union sockaddr_union *,
+ union sockaddr_union *);
int ipsec6_input(struct mbuf *, int, int);
int ipsec6_in_reject(const struct mbuf *, struct inpcb *);
int ipsec6_forward(struct mbuf *);
Modified: projects/ipsec/sys/netipsec/subr_ipsec.c
==============================================================================
--- projects/ipsec/sys/netipsec/subr_ipsec.c Sat Dec 24 17:42:34 2016 (r310524)
+++ projects/ipsec/sys/netipsec/subr_ipsec.c Sat Dec 24 20:02:28 2016 (r310525)
@@ -104,6 +104,69 @@ DECLARE_MODULE(ipsec_support, ipsec_supp
SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);
MODULE_VERSION(ipsec_support, 1);
+#ifdef INET
+void
+ipsec4_setsockaddrs(const struct mbuf *m, union sockaddr_union *src,
+ union sockaddr_union *dst)
+{
+ static const struct sockaddr_in template = {
+ sizeof (struct sockaddr_in),
+ AF_INET,
+ 0, { 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }
+ };
+
+ src->sin = template;
+ dst->sin = template;
+
+ if (m->m_len < sizeof (struct ip)) {
+ m_copydata(m, offsetof(struct ip, ip_src),
+ sizeof (struct in_addr),
+ (caddr_t) &src->sin.sin_addr);
+ m_copydata(m, offsetof(struct ip, ip_dst),
+ sizeof (struct in_addr),
+ (caddr_t) &dst->sin.sin_addr);
+ } else {
+ const struct ip *ip = mtod(m, const struct ip *);
+ src->sin.sin_addr = ip->ip_src;
+ dst->sin.sin_addr = ip->ip_dst;
+ }
+}
+#endif
+#ifdef INET6
+void
+ipsec6_setsockaddrs(const struct mbuf *m, union sockaddr_union *src,
+ union sockaddr_union *dst)
+{
+ struct ip6_hdr ip6buf;
+ const struct ip6_hdr *ip6;
+
+ if (m->m_len >= sizeof(*ip6))
+ ip6 = mtod(m, const struct ip6_hdr *);
+ else {
+ m_copydata(m, 0, sizeof(ip6buf), (caddr_t)&ip6buf);
+ ip6 = &ip6buf;
+ }
+
+ bzero(&src->sin6, sizeof(struct sockaddr_in6));
+ src->sin6.sin6_family = AF_INET6;
+ src->sin6.sin6_len = sizeof(struct sockaddr_in6);
+ bcopy(&ip6->ip6_src, &src->sin6.sin6_addr, sizeof(ip6->ip6_src));
+ if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src)) {
+ src->sin6.sin6_addr.s6_addr16[1] = 0;
+ src->sin6.sin6_scope_id = ntohs(ip6->ip6_src.s6_addr16[1]);
+ }
+
+ bzero(&dst->sin6, sizeof(struct sockaddr_in6));
+ dst->sin6.sin6_family = AF_INET6;
+ dst->sin6.sin6_len = sizeof(struct sockaddr_in6);
+ bcopy(&ip6->ip6_dst, &dst->sin6.sin6_addr, sizeof(ip6->ip6_dst));
+ if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst)) {
+ dst->sin6.sin6_addr.s6_addr16[1] = 0;
+ dst->sin6.sin6_scope_id = ntohs(ip6->ip6_dst.s6_addr16[1]);
+ }
+}
+#endif
+
#ifdef TCP_SIGNATURE
const int tcp_ipsec_support = 1;
#else
More information about the svn-src-projects
mailing list