ip_encap.c (201145) | ip_encap.c (269699) |
---|---|
1/* $KAME: ip_encap.c,v 1.41 2001/03/15 08:35:08 itojun Exp $ */ 2 3/*- 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 43 unchanged lines hidden (view full) --- 52 * AH/ESP/IPComp header right after outer IP header. 53 * 54 * So, clearly good old protosw does not work for protocol #4 and #41. 55 * The code will let you match protocol via src/dst address pair. 56 */ 57/* XXX is M_NETADDR correct? */ 58 59#include <sys/cdefs.h> | 1/* $KAME: ip_encap.c,v 1.41 2001/03/15 08:35:08 itojun Exp $ */ 2 3/*- 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 43 unchanged lines hidden (view full) --- 52 * AH/ESP/IPComp header right after outer IP header. 53 * 54 * So, clearly good old protosw does not work for protocol #4 and #41. 55 * The code will let you match protocol via src/dst address pair. 56 */ 57/* XXX is M_NETADDR correct? */ 58 59#include <sys/cdefs.h> |
60__FBSDID("$FreeBSD: head/sys/netinet/ip_encap.c 201145 2009-12-28 22:56:30Z antoine $"); | 60__FBSDID("$FreeBSD: head/sys/netinet/ip_encap.c 269699 2014-08-08 01:57:15Z kevlo $"); |
61 62#include "opt_mrouting.h" 63#include "opt_inet.h" 64#include "opt_inet6.h" 65 66#include <sys/param.h> 67#include <sys/systm.h> 68#include <sys/socket.h> --- 10 unchanged lines hidden (view full) --- 79#include <netinet/in_systm.h> 80#include <netinet/ip.h> 81#include <netinet/ip_var.h> 82#include <netinet/ip_encap.h> 83 84#ifdef INET6 85#include <netinet/ip6.h> 86#include <netinet6/ip6_var.h> | 61 62#include "opt_mrouting.h" 63#include "opt_inet.h" 64#include "opt_inet6.h" 65 66#include <sys/param.h> 67#include <sys/systm.h> 68#include <sys/socket.h> --- 10 unchanged lines hidden (view full) --- 79#include <netinet/in_systm.h> 80#include <netinet/ip.h> 81#include <netinet/ip_var.h> 82#include <netinet/ip_encap.h> 83 84#ifdef INET6 85#include <netinet/ip6.h> 86#include <netinet6/ip6_var.h> |
87#include <netinet6/ip6protosw.h> | |
88#endif 89 90#include <machine/stdarg.h> 91 92#include <sys/kernel.h> 93#include <sys/malloc.h> 94static MALLOC_DEFINE(M_NETADDR, "encap_export_host", "Export host address structure"); 95 --- 14 unchanged lines hidden (view full) --- 110 * it's referenced by KAME pieces in netinet6. 111 */ 112void 113encap_init(void) 114{ 115} 116 117#ifdef INET | 87#endif 88 89#include <machine/stdarg.h> 90 91#include <sys/kernel.h> 92#include <sys/malloc.h> 93static MALLOC_DEFINE(M_NETADDR, "encap_export_host", "Export host address structure"); 94 --- 14 unchanged lines hidden (view full) --- 109 * it's referenced by KAME pieces in netinet6. 110 */ 111void 112encap_init(void) 113{ 114} 115 116#ifdef INET |
118void 119encap4_input(struct mbuf *m, int off) | 117int 118encap4_input(struct mbuf **mp, int *offp, int proto) |
120{ 121 struct ip *ip; | 119{ 120 struct ip *ip; |
122 int proto; | 121 struct mbuf *m; |
123 struct sockaddr_in s, d; 124 const struct protosw *psw; 125 struct encaptab *ep, *match; | 122 struct sockaddr_in s, d; 123 const struct protosw *psw; 124 struct encaptab *ep, *match; |
126 int prio, matchprio; | 125 int matchprio, off, prio; |
127 | 126 |
127 m = *mp; 128 off = *offp; |
|
128 ip = mtod(m, struct ip *); | 129 ip = mtod(m, struct ip *); |
129 proto = ip->ip_p; | 130 *mp = NULL; |
130 131 bzero(&s, sizeof(s)); 132 s.sin_family = AF_INET; 133 s.sin_len = sizeof(struct sockaddr_in); 134 s.sin_addr = ip->ip_src; 135 bzero(&d, sizeof(d)); 136 d.sin_family = AF_INET; 137 d.sin_len = sizeof(struct sockaddr_in); --- 45 unchanged lines hidden (view full) --- 183 } 184 mtx_unlock(&encapmtx); 185 186 if (match) { 187 /* found a match, "match" has the best one */ 188 psw = match->psw; 189 if (psw && psw->pr_input) { 190 encap_fillarg(m, match); | 131 132 bzero(&s, sizeof(s)); 133 s.sin_family = AF_INET; 134 s.sin_len = sizeof(struct sockaddr_in); 135 s.sin_addr = ip->ip_src; 136 bzero(&d, sizeof(d)); 137 d.sin_family = AF_INET; 138 d.sin_len = sizeof(struct sockaddr_in); --- 45 unchanged lines hidden (view full) --- 184 } 185 mtx_unlock(&encapmtx); 186 187 if (match) { 188 /* found a match, "match" has the best one */ 189 psw = match->psw; 190 if (psw && psw->pr_input) { 191 encap_fillarg(m, match); |
191 (*psw->pr_input)(m, off); | 192 *mp = m; 193 (*psw->pr_input)(mp, offp, proto); |
192 } else 193 m_freem(m); | 194 } else 195 m_freem(m); |
194 return; | 196 return (IPPROTO_DONE); |
195 } 196 197 /* last resort: inject to raw socket */ | 197 } 198 199 /* last resort: inject to raw socket */ |
198 rip_input(m, off); | 200 *mp = m; 201 return (rip_input(mp, offp, proto)); |
199} 200#endif 201 202#ifdef INET6 203int 204encap6_input(struct mbuf **mp, int *offp, int proto) 205{ 206 struct mbuf *m = *mp; 207 struct ip6_hdr *ip6; 208 struct sockaddr_in6 s, d; | 202} 203#endif 204 205#ifdef INET6 206int 207encap6_input(struct mbuf **mp, int *offp, int proto) 208{ 209 struct mbuf *m = *mp; 210 struct ip6_hdr *ip6; 211 struct sockaddr_in6 s, d; |
209 const struct ip6protosw *psw; | 212 const struct protosw *psw; |
210 struct encaptab *ep, *match; 211 int prio, matchprio; 212 213 ip6 = mtod(m, struct ip6_hdr *); 214 215 bzero(&s, sizeof(s)); 216 s.sin6_family = AF_INET6; 217 s.sin6_len = sizeof(struct sockaddr_in6); --- 29 unchanged lines hidden (view full) --- 247 matchprio = prio; 248 match = ep; 249 } 250 } 251 mtx_unlock(&encapmtx); 252 253 if (match) { 254 /* found a match */ | 213 struct encaptab *ep, *match; 214 int prio, matchprio; 215 216 ip6 = mtod(m, struct ip6_hdr *); 217 218 bzero(&s, sizeof(s)); 219 s.sin6_family = AF_INET6; 220 s.sin6_len = sizeof(struct sockaddr_in6); --- 29 unchanged lines hidden (view full) --- 250 matchprio = prio; 251 match = ep; 252 } 253 } 254 mtx_unlock(&encapmtx); 255 256 if (match) { 257 /* found a match */ |
255 psw = (const struct ip6protosw *)match->psw; | 258 psw = match->psw; |
256 if (psw && psw->pr_input) { 257 encap_fillarg(m, match); 258 return (*psw->pr_input)(mp, offp, proto); 259 } else { 260 m_freem(m); 261 return IPPROTO_DONE; 262 } 263 } --- 200 unchanged lines hidden --- | 259 if (psw && psw->pr_input) { 260 encap_fillarg(m, match); 261 return (*psw->pr_input)(mp, offp, proto); 262 } else { 263 m_freem(m); 264 return IPPROTO_DONE; 265 } 266 } --- 200 unchanged lines hidden --- |