Deleted Added
full compact
in_gif.c (269054) in_gif.c (269699)
1/* $KAME: in_gif.c,v 1.54 2001/05/14 14:02:16 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

--- 16 unchanged lines hidden (view full) ---

25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
1/* $KAME: in_gif.c,v 1.54 2001/05/14 14:02:16 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

--- 16 unchanged lines hidden (view full) ---

25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/netinet/in_gif.c 269054 2014-07-24 10:42:47Z hrs $");
33__FBSDID("$FreeBSD: head/sys/netinet/in_gif.c 269699 2014-08-08 01:57:15Z kevlo $");
34
35#include "opt_mrouting.h"
36#include "opt_inet.h"
37#include "opt_inet6.h"
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/socket.h>

--- 34 unchanged lines hidden (view full) ---

76
77extern struct domain inetdomain;
78struct protosw in_gif_protosw = {
79 .pr_type = SOCK_RAW,
80 .pr_domain = &inetdomain,
81 .pr_protocol = 0/* IPPROTO_IPV[46] */,
82 .pr_flags = PR_ATOMIC|PR_ADDR,
83 .pr_input = in_gif_input,
34
35#include "opt_mrouting.h"
36#include "opt_inet.h"
37#include "opt_inet6.h"
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/socket.h>

--- 34 unchanged lines hidden (view full) ---

76
77extern struct domain inetdomain;
78struct protosw in_gif_protosw = {
79 .pr_type = SOCK_RAW,
80 .pr_domain = &inetdomain,
81 .pr_protocol = 0/* IPPROTO_IPV[46] */,
82 .pr_flags = PR_ATOMIC|PR_ADDR,
83 .pr_input = in_gif_input,
84 .pr_output = (pr_output_t*)rip_output,
84 .pr_output = (pr_output_t *)rip_output,
85 .pr_ctloutput = rip_ctloutput,
86 .pr_usrreqs = &rip_usrreqs
87};
88
89VNET_DEFINE(int, ip_gif_ttl) = GIF_TTL;
90#define V_ip_gif_ttl VNET(ip_gif_ttl)
91SYSCTL_VNET_INT(_net_inet_ip, IPCTL_GIF_TTL, gifttl, CTLFLAG_RW,
92 &VNET_NAME(ip_gif_ttl), 0, "");

--- 172 unchanged lines hidden (view full) ---

265 sc->gif_ro.ro_rt != NULL) {
266 RTFREE(sc->gif_ro.ro_rt);
267 sc->gif_ro.ro_rt = NULL;
268 }
269
270 return (error);
271}
272
85 .pr_ctloutput = rip_ctloutput,
86 .pr_usrreqs = &rip_usrreqs
87};
88
89VNET_DEFINE(int, ip_gif_ttl) = GIF_TTL;
90#define V_ip_gif_ttl VNET(ip_gif_ttl)
91SYSCTL_VNET_INT(_net_inet_ip, IPCTL_GIF_TTL, gifttl, CTLFLAG_RW,
92 &VNET_NAME(ip_gif_ttl), 0, "");

--- 172 unchanged lines hidden (view full) ---

265 sc->gif_ro.ro_rt != NULL) {
266 RTFREE(sc->gif_ro.ro_rt);
267 sc->gif_ro.ro_rt = NULL;
268 }
269
270 return (error);
271}
272
273void
274in_gif_input(struct mbuf *m, int off)
273int
274in_gif_input(struct mbuf **mp, int *offp, int proto)
275{
275{
276 struct mbuf *m;
276 struct ifnet *gifp = NULL;
277 struct gif_softc *sc;
278 struct ip *ip;
279 int af;
277 struct ifnet *gifp = NULL;
278 struct gif_softc *sc;
279 struct ip *ip;
280 int af;
281 int off;
280 u_int8_t otos;
282 u_int8_t otos;
281 int proto;
282
283
284 m = *mp;
283 ip = mtod(m, struct ip *);
285 ip = mtod(m, struct ip *);
284 proto = ip->ip_p;
286 off = *offp;
287 *mp = NULL;
285
286 sc = (struct gif_softc *)encap_getarg(m);
287 if (sc == NULL) {
288 m_freem(m);
289 KMOD_IPSTAT_INC(ips_nogif);
288
289 sc = (struct gif_softc *)encap_getarg(m);
290 if (sc == NULL) {
291 m_freem(m);
292 KMOD_IPSTAT_INC(ips_nogif);
290 return;
293 return (IPPROTO_DONE);
291 }
292
293 gifp = GIF2IFP(sc);
294 if (gifp == NULL || (gifp->if_flags & IFF_UP) == 0) {
295 m_freem(m);
296 KMOD_IPSTAT_INC(ips_nogif);
294 }
295
296 gifp = GIF2IFP(sc);
297 if (gifp == NULL || (gifp->if_flags & IFF_UP) == 0) {
298 m_freem(m);
299 KMOD_IPSTAT_INC(ips_nogif);
297 return;
300 return (IPPROTO_DONE);
298 }
299
300 otos = ip->ip_tos;
301 m_adj(m, off);
302
303 switch (proto) {
304#ifdef INET
305 case IPPROTO_IPV4:
306 {
307 struct ip *ip;
308 af = AF_INET;
309 if (m->m_len < sizeof(*ip)) {
310 m = m_pullup(m, sizeof(*ip));
311 if (!m)
301 }
302
303 otos = ip->ip_tos;
304 m_adj(m, off);
305
306 switch (proto) {
307#ifdef INET
308 case IPPROTO_IPV4:
309 {
310 struct ip *ip;
311 af = AF_INET;
312 if (m->m_len < sizeof(*ip)) {
313 m = m_pullup(m, sizeof(*ip));
314 if (!m)
312 return;
315 return (IPPROTO_DONE);
313 }
314 ip = mtod(m, struct ip *);
315 if (ip_ecn_egress((gifp->if_flags & IFF_LINK1) ?
316 ECN_ALLOWED : ECN_NOCARE,
317 &otos, &ip->ip_tos) == 0) {
318 m_freem(m);
316 }
317 ip = mtod(m, struct ip *);
318 if (ip_ecn_egress((gifp->if_flags & IFF_LINK1) ?
319 ECN_ALLOWED : ECN_NOCARE,
320 &otos, &ip->ip_tos) == 0) {
321 m_freem(m);
319 return;
322 return (IPPROTO_DONE);
320 }
321 break;
322 }
323#endif
324#ifdef INET6
325 case IPPROTO_IPV6:
326 {
327 struct ip6_hdr *ip6;
328 u_int8_t itos, oitos;
329
330 af = AF_INET6;
331 if (m->m_len < sizeof(*ip6)) {
332 m = m_pullup(m, sizeof(*ip6));
333 if (!m)
323 }
324 break;
325 }
326#endif
327#ifdef INET6
328 case IPPROTO_IPV6:
329 {
330 struct ip6_hdr *ip6;
331 u_int8_t itos, oitos;
332
333 af = AF_INET6;
334 if (m->m_len < sizeof(*ip6)) {
335 m = m_pullup(m, sizeof(*ip6));
336 if (!m)
334 return;
337 return (IPPROTO_DONE);
335 }
336 ip6 = mtod(m, struct ip6_hdr *);
337 itos = oitos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
338 if (ip_ecn_egress((gifp->if_flags & IFF_LINK1) ?
339 ECN_ALLOWED : ECN_NOCARE,
340 &otos, &itos) == 0) {
341 m_freem(m);
338 }
339 ip6 = mtod(m, struct ip6_hdr *);
340 itos = oitos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
341 if (ip_ecn_egress((gifp->if_flags & IFF_LINK1) ?
342 ECN_ALLOWED : ECN_NOCARE,
343 &otos, &itos) == 0) {
344 m_freem(m);
342 return;
345 return (IPPROTO_DONE);
343 }
344 if (itos != oitos) {
345 ip6->ip6_flow &= ~htonl(0xff << 20);
346 ip6->ip6_flow |= htonl((u_int32_t)itos << 20);
347 }
348 break;
349 }
350#endif /* INET6 */
351 case IPPROTO_ETHERIP:
352 af = AF_LINK;
353 break;
354
355 default:
356 KMOD_IPSTAT_INC(ips_nogif);
357 m_freem(m);
346 }
347 if (itos != oitos) {
348 ip6->ip6_flow &= ~htonl(0xff << 20);
349 ip6->ip6_flow |= htonl((u_int32_t)itos << 20);
350 }
351 break;
352 }
353#endif /* INET6 */
354 case IPPROTO_ETHERIP:
355 af = AF_LINK;
356 break;
357
358 default:
359 KMOD_IPSTAT_INC(ips_nogif);
360 m_freem(m);
358 return;
361 return (IPPROTO_DONE);
359 }
360 gif_input(m, af, gifp);
362 }
363 gif_input(m, af, gifp);
361 return;
364 return (IPPROTO_DONE);
362}
363
364/*
365 * validate outer address.
366 */
367static int
368gif_validate4(const struct ip *ip, struct gif_softc *sc, struct ifnet *ifp)
369{

--- 101 unchanged lines hidden ---
365}
366
367/*
368 * validate outer address.
369 */
370static int
371gif_validate4(const struct ip *ip, struct gif_softc *sc, struct ifnet *ifp)
372{

--- 101 unchanged lines hidden ---