Deleted Added
full compact
if_gre.c (178888) if_gre.c (179894)
1/* $NetBSD: if_gre.c,v 1.49 2003/12/11 00:22:29 itojun Exp $ */
1/* $NetBSD: if_gre.c,v 1.49 2003/12/11 00:22:29 itojun Exp $ */
2/* $FreeBSD: head/sys/net/if_gre.c 178888 2008-05-09 23:03:00Z julian $ */
2/* $FreeBSD: head/sys/net/if_gre.c 179894 2008-06-20 17:26:34Z thompsa $ */
3
4/*-
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Heiko W.Rupp <hwr@pilhuhn.de>
10 *

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

199 GRE2IFP(sc)->if_ioctl = gre_ioctl;
200 sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY;
201 sc->g_proto = IPPROTO_GRE;
202 GRE2IFP(sc)->if_flags |= IFF_LINK0;
203 sc->encap = NULL;
204 sc->called = 0;
205 sc->gre_fibnum = curthread->td_proc->p_fibnum;
206 sc->wccp_ver = WCCP_V1;
3
4/*-
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Heiko W.Rupp <hwr@pilhuhn.de>
10 *

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

199 GRE2IFP(sc)->if_ioctl = gre_ioctl;
200 sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY;
201 sc->g_proto = IPPROTO_GRE;
202 GRE2IFP(sc)->if_flags |= IFF_LINK0;
203 sc->encap = NULL;
204 sc->called = 0;
205 sc->gre_fibnum = curthread->td_proc->p_fibnum;
206 sc->wccp_ver = WCCP_V1;
207 sc->key = 0;
207 if_attach(GRE2IFP(sc));
208 bpfattach(GRE2IFP(sc), DLT_NULL, sizeof(u_int32_t));
209 mtx_lock(&gre_mtx);
210 LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list);
211 mtx_unlock(&gre_mtx);
212 return (0);
213}
214

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

378 break;
379#endif
380 default:
381 _IF_DROP(&ifp->if_snd);
382 m_freem(m);
383 error = EAFNOSUPPORT;
384 goto end;
385 }
208 if_attach(GRE2IFP(sc));
209 bpfattach(GRE2IFP(sc), DLT_NULL, sizeof(u_int32_t));
210 mtx_lock(&gre_mtx);
211 LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list);
212 mtx_unlock(&gre_mtx);
213 return (0);
214}
215

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

379 break;
380#endif
381 default:
382 _IF_DROP(&ifp->if_snd);
383 m_freem(m);
384 error = EAFNOSUPPORT;
385 goto end;
386 }
386 M_PREPEND(m, sizeof(struct greip), M_DONTWAIT);
387
388 /* Reserve space for GRE header + optional GRE key */
389 int hdrlen = sizeof(struct greip);
390 if (sc->key)
391 hdrlen += sizeof(uint32_t);
392 M_PREPEND(m, hdrlen, M_DONTWAIT);
387 } else {
388 _IF_DROP(&ifp->if_snd);
389 m_freem(m);
390 error = EINVAL;
391 goto end;
392 }
393
394 if (m == NULL) { /* mbuf allocation failed */
395 _IF_DROP(&ifp->if_snd);
396 error = ENOBUFS;
397 goto end;
398 }
399
400 M_SETFIB(m, sc->gre_fibnum); /* The envelope may use a different FIB */
401
402 gh = mtod(m, struct greip *);
403 if (sc->g_proto == IPPROTO_GRE) {
393 } else {
394 _IF_DROP(&ifp->if_snd);
395 m_freem(m);
396 error = EINVAL;
397 goto end;
398 }
399
400 if (m == NULL) { /* mbuf allocation failed */
401 _IF_DROP(&ifp->if_snd);
402 error = ENOBUFS;
403 goto end;
404 }
405
406 M_SETFIB(m, sc->gre_fibnum); /* The envelope may use a different FIB */
407
408 gh = mtod(m, struct greip *);
409 if (sc->g_proto == IPPROTO_GRE) {
404 /* we don't have any GRE flags for now */
410 uint32_t *options = gh->gi_options;
411
405 memset((void *)gh, 0, sizeof(struct greip));
406 gh->gi_ptype = htons(etype);
412 memset((void *)gh, 0, sizeof(struct greip));
413 gh->gi_ptype = htons(etype);
414 gh->gi_flags = 0;
415
416 /* Add key option */
417 if (sc->key)
418 {
419 gh->gi_flags |= htons(GRE_KP);
420 *(options++) = htonl(sc->key);
421 }
407 }
408
409 gh->gi_pr = sc->g_proto;
410 if (sc->g_proto != IPPROTO_MOBILE) {
411 gh->gi_src = sc->g_src;
412 gh->gi_dst = sc->g_dst;
413 ((struct ip*)gh)->ip_v = IPPROTO_IPV4;
414 ((struct ip*)gh)->ip_hl = (sizeof(struct ip)) >> 2;

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

439{
440 struct ifreq *ifr = (struct ifreq *)data;
441 struct if_laddrreq *lifr = (struct if_laddrreq *)data;
442 struct in_aliasreq *aifr = (struct in_aliasreq *)data;
443 struct gre_softc *sc = ifp->if_softc;
444 int s;
445 struct sockaddr_in si;
446 struct sockaddr *sa = NULL;
422 }
423
424 gh->gi_pr = sc->g_proto;
425 if (sc->g_proto != IPPROTO_MOBILE) {
426 gh->gi_src = sc->g_src;
427 gh->gi_dst = sc->g_dst;
428 ((struct ip*)gh)->ip_v = IPPROTO_IPV4;
429 ((struct ip*)gh)->ip_hl = (sizeof(struct ip)) >> 2;

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

454{
455 struct ifreq *ifr = (struct ifreq *)data;
456 struct if_laddrreq *lifr = (struct if_laddrreq *)data;
457 struct in_aliasreq *aifr = (struct in_aliasreq *)data;
458 struct gre_softc *sc = ifp->if_softc;
459 int s;
460 struct sockaddr_in si;
461 struct sockaddr *sa = NULL;
447 int error;
462 int error, adj;
448 struct sockaddr_in sp, sm, dp, dm;
463 struct sockaddr_in sp, sm, dp, dm;
464 uint32_t key;
449
450 error = 0;
465
466 error = 0;
467 adj = 0;
451
452 s = splnet();
453 switch (cmd) {
454 case SIOCSIFADDR:
455 ifp->if_flags |= IFF_UP;
456 break;
457 case SIOCSIFDSTADDR:
458 break;

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

717 break;
718 }
719 memset(&si, 0, sizeof(si));
720 si.sin_family = AF_INET;
721 si.sin_len = sizeof(struct sockaddr_in);
722 si.sin_addr.s_addr = sc->g_dst.s_addr;
723 bcopy(&si, &ifr->ifr_addr, sizeof(ifr->ifr_addr));
724 break;
468
469 s = splnet();
470 switch (cmd) {
471 case SIOCSIFADDR:
472 ifp->if_flags |= IFF_UP;
473 break;
474 case SIOCSIFDSTADDR:
475 break;

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

734 break;
735 }
736 memset(&si, 0, sizeof(si));
737 si.sin_family = AF_INET;
738 si.sin_len = sizeof(struct sockaddr_in);
739 si.sin_addr.s_addr = sc->g_dst.s_addr;
740 bcopy(&si, &ifr->ifr_addr, sizeof(ifr->ifr_addr));
741 break;
742 case GRESKEY:
743 error = priv_check(curthread, PRIV_NET_GRE);
744 if (error)
745 break;
746 error = copyin(ifr->ifr_data, &key, sizeof(key));
747 if (error)
748 break;
749 /* adjust MTU for option header */
750 if (key == 0 && sc->key != 0) /* clear */
751 adj += sizeof(key);
752 else if (key != 0 && sc->key == 0) /* set */
753 adj -= sizeof(key);
754
755 if (ifp->if_mtu + adj < 576) {
756 error = EINVAL;
757 break;
758 }
759 ifp->if_mtu += adj;
760 sc->key = key;
761 break;
762 case GREGKEY:
763 error = copyout(&sc->key, ifr->ifr_data, sizeof(sc->key));
764 break;
765
725 default:
726 error = EINVAL;
727 break;
728 }
729
730 splx(s);
731 return (error);
732}

--- 127 unchanged lines hidden ---
766 default:
767 error = EINVAL;
768 break;
769 }
770
771 splx(s);
772 return (error);
773}

--- 127 unchanged lines hidden ---