From owner-svn-src-head@FreeBSD.ORG Sun Jun 7 23:00:41 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3C4881065672; Sun, 7 Jun 2009 23:00:41 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 27E378FC1F; Sun, 7 Jun 2009 23:00:41 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n57N0fdY008331; Sun, 7 Jun 2009 23:00:41 GMT (envelope-from hrs@svn.freebsd.org) Received: (from hrs@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n57N0ems008322; Sun, 7 Jun 2009 23:00:40 GMT (envelope-from hrs@svn.freebsd.org) Message-Id: <200906072300.n57N0ems008322@svn.freebsd.org> From: Hiroki Sato Date: Sun, 7 Jun 2009 23:00:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r193664 - in head: sbin/ifconfig share/man/man4 sys/net sys/netinet sys/netinet6 sys/sys X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jun 2009 23:00:41 -0000 Author: hrs Date: Sun Jun 7 23:00:40 2009 New Revision: 193664 URL: http://svn.freebsd.org/changeset/base/193664 Log: Fix and add a workaround on an issue of EtherIP packet with reversed version field sent via gif(4)+if_bridge(4). The EtherIP implementation found on FreeBSD 6.1, 6.2, 6.3, 7.0, 7.1, and 7.2 had an interoperability issue because it sent the incorrect EtherIP packets and discarded the correct ones. This change introduces the following two flags to gif(4): accept_rev_ethip_ver: accepts both correct EtherIP packets and ones with reversed version field, if enabled. If disabled, the gif accepts the correct packets only. This flag is enabled by default. send_rev_ethip_ver: sends EtherIP packets with reversed version field intentionally, if enabled. If disabled, the gif sends the correct packets only. This flag is disabled by default. These flags are stored in struct gif_softc and can be set by ifconfig(8) on per-interface basis. Note that this is an incompatible change of EtherIP with the older FreeBSD releases. If you need to interoperate older FreeBSD boxes and new versions after this commit, setting "send_rev_ethip_ver" is needed. Reviewed by: thompsa and rwatson Spotted by: Shunsuke SHINOMIYA PR: kern/125003 MFC after: 2 weeks Added: head/sbin/ifconfig/ifgif.c (contents, props changed) Modified: head/sbin/ifconfig/Makefile head/share/man/man4/gif.4 head/share/man/man4/if_bridge.4 head/sys/net/if_gif.c head/sys/net/if_gif.h head/sys/netinet/in_gif.c head/sys/netinet6/in6_gif.c head/sys/sys/priv.h Modified: head/sbin/ifconfig/Makefile ============================================================================== --- head/sbin/ifconfig/Makefile Sun Jun 7 22:55:48 2009 (r193663) +++ head/sbin/ifconfig/Makefile Sun Jun 7 23:00:40 2009 (r193664) @@ -24,6 +24,7 @@ SRCS+= ifmac.c # MAC support SRCS+= ifmedia.c # SIOC[GS]IFMEDIA support SRCS+= ifvlan.c # SIOC[GS]ETVLAN support SRCS+= ifgre.c # GRE keys etc +SRCS+= ifgif.c # GIF reversed header workaround SRCS+= ifieee80211.c regdomain.c # SIOC[GS]IEEE80211 support DPADD+= ${LIBBSDXML} ${LIBSBUF} Added: head/sbin/ifconfig/ifgif.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sbin/ifconfig/ifgif.c Sun Jun 7 23:00:40 2009 (r193664) @@ -0,0 +1,132 @@ +/*- + * Copyright (c) 2009 Hiroki Sato. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef lint +static const char rcsid[] = + "$FreeBSD$"; +#endif + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "ifconfig.h" + +static void gif_status(int); + +static struct { + const char *label; + u_int mask; +} gif_opts[] = { + { "ACCEPT_REV_ETHIP_VER", GIF_ACCEPT_REVETHIP }, + { "SEND_REV_ETHIP_VER", GIF_SEND_REVETHIP }, +}; + +static void +gif_status(int s) +{ + int opts; + int nopts = 0; + int i; + + ifr.ifr_data = (caddr_t)&opts; + if (ioctl(s, GIFGOPTS, &ifr) == -1) + return; + + printf("\toptions=%d<", opts); + for (i=0; i < sizeof(gif_opts)/sizeof(gif_opts[0]); i++) { + if (opts & gif_opts[i].mask) { + if (nopts++) + printf(","); + printf("%s", gif_opts[i].label); + } + } + printf(">\n"); +} + +static void +setgifopts(const char *val, + int d, int s, const struct afswtch *afp) +{ + int opts; + + ifr.ifr_data = (caddr_t)&opts; + if (ioctl(s, GIFGOPTS, &ifr) == -1) { + warn("ioctl(GIFGOPTS)"); + return; + } + + if (d < 0) + opts &= ~(-d); + else + opts |= d; + + if (ioctl(s, GIFSOPTS, &ifr) == -1) { + warn("ioctl(GIFSOPTS)"); + return; + } +} + +static struct cmd gif_cmds[] = { + DEF_CMD("accept_rev_ethip_ver", GIF_ACCEPT_REVETHIP, setgifopts), + DEF_CMD("-accept_rev_ethip_ver",-GIF_ACCEPT_REVETHIP, setgifopts), + DEF_CMD("send_rev_ethip_ver", GIF_SEND_REVETHIP, setgifopts), + DEF_CMD("-send_rev_ethip_ver", -GIF_SEND_REVETHIP, setgifopts), +}; + +static struct afswtch af_gif = { + .af_name = "af_gif", + .af_af = AF_UNSPEC, + .af_other_status = gif_status, +}; + +static __constructor void +gif_ctor(void) +{ +#define N(a) (sizeof(a) / sizeof(a[0])) + int i; + + for (i = 0; i < N(gif_cmds); i++) + cmd_register(&gif_cmds[i]); + af_register(&af_gif); +#undef N +} Modified: head/share/man/man4/gif.4 ============================================================================== --- head/share/man/man4/gif.4 Sun Jun 7 22:55:48 2009 (r193663) +++ head/share/man/man4/gif.4 Sun Jun 7 23:00:40 2009 (r193664) @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 10, 1999 +.Dd June 8, 2009 .Dt GIF 4 .Os .Sh NAME @@ -256,3 +256,32 @@ had a multi-destination behavior, config .Dv IFF_LINK0 flag. The behavior is obsolete and is no longer supported. +.Pp +On +.Fx +6.1, 6.2, 6.3, 7.0, 7.1, and 7.2 +the +.Nm +sends and receives incorrect EtherIP packets with reversed version +field when +.Xr if_bridge 4 +is used together. As a workaround on this interoperability issue, the +following two +.Xr ifconfig 8 +flags can be used: +.Bl -tag -width "accept_rev_ethip_ver" -offset indent +.It accept_rev_ethip_ver +accepts both correct EtherIP packets and ones with reversed version +field, if enabled. If disabled, the +.Nm +accepts the correct packets only. This flag is enabled by default. +.It send_rev_ethip_ver +sends EtherIP packets with reversed version field intentionally, if +enabled. If disabled, the +.Nm +sends the correct packets only. This flag is disabled by default. +.El +.Pp +If interoperability with the older +.Fx +machines is needed, both of these two flags must be enabled. Modified: head/share/man/man4/if_bridge.4 ============================================================================== --- head/share/man/man4/if_bridge.4 Sun Jun 7 22:55:48 2009 (r193663) +++ head/share/man/man4/if_bridge.4 Sun Jun 7 23:00:40 2009 (r193664) @@ -35,7 +35,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 17, 2007 +.Dd June 8, 2009 .Dt IF_BRIDGE 4 .Os .Sh NAME @@ -406,6 +406,12 @@ ifconfig gif0 tunnel 1.2.3.4 5.6.7.8 up ifconfig bridge0 create ifconfig bridge0 addm fxp0 addm gif0 up .Ed +.Pp +Note that +.Fx +6.1, 6.2, 6.3, 7.0, 7.1, and 7.2 have a bug in the EtherIP protocol. +For more details and workaround, see +.Xr gif 4 manual page. .Sh SEE ALSO .Xr gif 4 , .Xr ipf 4 , Modified: head/sys/net/if_gif.c ============================================================================== --- head/sys/net/if_gif.c Sun Jun 7 22:55:48 2009 (r193663) +++ head/sys/net/if_gif.c Sun Jun 7 23:00:40 2009 (r193664) @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -198,6 +199,7 @@ gif_clone_create(ifc, unit, params) if_initname(GIF2IFP(sc), ifc->ifc_name, unit); sc->encap_cookie4 = sc->encap_cookie6 = NULL; + sc->gif_options = GIF_ACCEPT_REVETHIP; GIF2IFP(sc)->if_addrlen = 0; GIF2IFP(sc)->if_mtu = GIF_MTU; @@ -534,6 +536,7 @@ gif_input(m, af, ifp) struct ifnet *ifp; { int isr, n; + struct gif_softc *sc = ifp->if_softc; struct etherip_header *eip; struct ether_header *eh; struct ifnet *oldifp; @@ -594,11 +597,25 @@ gif_input(m, af, ifp) } eip = mtod(m, struct etherip_header *); - if (eip->eip_ver != - (ETHERIP_VERSION & ETHERIP_VER_VERS_MASK)) { - /* discard unknown versions */ - m_freem(m); - return; + /* + * GIF_ACCEPT_REVETHIP (enabled by default) intentionally + * accepts an EtherIP packet with revered version field in + * the header. This is a knob for backward compatibility + * with FreeBSD 7.2R or prior. + */ + if (sc->gif_options & GIF_ACCEPT_REVETHIP) { + if (eip->eip_resvl != ETHERIP_VERSION + && eip->eip_ver != ETHERIP_VERSION) { + /* discard unknown versions */ + m_freem(m); + return; + } + } else { + if (eip->eip_ver != ETHERIP_VERSION) { + /* discard unknown versions */ + m_freem(m); + return; + } } m_adj(m, sizeof(struct etherip_header)); @@ -653,6 +670,7 @@ gif_ioctl(ifp, cmd, data) struct gif_softc *sc = ifp->if_softc; struct ifreq *ifr = (struct ifreq*)data; int error = 0, size; + u_int options; struct sockaddr *dst, *src; #ifdef SIOCSIFMTU /* xxx */ u_long mtu; @@ -887,6 +905,24 @@ gif_ioctl(ifp, cmd, data) /* if_ioctl() takes care of it */ break; + case GIFGOPTS: + options = sc->gif_options; + error = copyout(&options, ifr->ifr_data, + sizeof(options)); + break; + + case GIFSOPTS: + if ((error = priv_check(curthread, PRIV_NET_GIF)) != 0) + break; + if ((error = copyin(&options, &sc->gif_options, + sizeof(sc->gif_options)))) { + if ((options | GIF_FULLOPTS) == GIF_FULLOPTS) + ifr->ifr_data = (caddr_t)options; + else + error = EINVAL; + } + break; + default: error = EINVAL; break; Modified: head/sys/net/if_gif.h ============================================================================== --- head/sys/net/if_gif.h Sun Jun 7 22:55:48 2009 (r193663) +++ head/sys/net/if_gif.h Sun Jun 7 23:00:40 2009 (r193664) @@ -71,6 +71,7 @@ struct gif_softc { const struct encaptab *encap_cookie4; const struct encaptab *encap_cookie6; void *gif_netgraph; /* ng_gif(4) netgraph node info */ + u_int gif_options; LIST_ENTRY(gif_softc) gif_list; /* all gif's are linked */ }; #define GIF2IFP(sc) ((sc)->gif_ifp) @@ -94,12 +95,18 @@ struct gif_softc { #define MTAG_GIF_CALLED 0 struct etherip_header { - u_int8_t eip_ver; /* version/reserved */ - u_int8_t eip_pad; /* required padding byte */ -}; -#define ETHERIP_VER_VERS_MASK 0x0f -#define ETHERIP_VER_RSVD_MASK 0xf0 -#define ETHERIP_VERSION 0x03 +#if BYTE_ORDER == LITTLE_ENDIAN + u_int eip_resvl:4, /* reserved */ + eip_ver:4; /* version */ +#endif +#if BYTE_ORDER == BIG_ENDIAN + u_int eip_ver:4, /* version */ + eip_resvl:4; /* reserved */ +#endif + u_int8_t eip_resvh; /* reserved */ +} __packed; + +#define ETHERIP_VERSION 0x3 /* mbuf adjust factor to force 32-bit alignment of IP header */ #define ETHERIP_ALIGN 2 @@ -143,4 +150,11 @@ extern struct vnet_gif vnet_gif_0; #endif /* _KERNEL */ +#define GIFGOPTS _IOR('i', 150, struct ifreq) +#define GIFSOPTS _IOW('i', 151, struct ifreq) + +#define GIF_ACCEPT_REVETHIP 0x0001 +#define GIF_SEND_REVETHIP 0x0010 +#define GIF_FULLOPTS (GIF_ACCEPT_REVETHIP|GIF_SEND_REVETHIP) + #endif /* _NET_IF_GIF_H_ */ Modified: head/sys/netinet/in_gif.c ============================================================================== --- head/sys/netinet/in_gif.c Sun Jun 7 22:55:48 2009 (r193663) +++ head/sys/netinet/in_gif.c Sun Jun 7 23:00:40 2009 (r193664) @@ -148,8 +148,22 @@ in_gif_output(struct ifnet *ifp, int fam #endif /* INET6 */ case AF_LINK: proto = IPPROTO_ETHERIP; - eiphdr.eip_ver = ETHERIP_VERSION & ETHERIP_VER_VERS_MASK; - eiphdr.eip_pad = 0; + + /* + * GIF_SEND_REVETHIP (disabled by default) intentionally + * sends an EtherIP packet with revered version field in + * the header. This is a knob for backward compatibility + * with FreeBSD 7.2R or prior. + */ + if ((sc->gif_options & GIF_SEND_REVETHIP)) { + eiphdr.eip_ver = 0; + eiphdr.eip_resvl = ETHERIP_VERSION; + eiphdr.eip_resvh = 0; + } else { + eiphdr.eip_ver = ETHERIP_VERSION; + eiphdr.eip_resvl = 0; + eiphdr.eip_resvh = 0; + } /* prepend Ethernet-in-IP header */ M_PREPEND(m, sizeof(struct etherip_header), M_DONTWAIT); if (m && m->m_len < sizeof(struct etherip_header)) Modified: head/sys/netinet6/in6_gif.c ============================================================================== --- head/sys/netinet6/in6_gif.c Sun Jun 7 22:55:48 2009 (r193663) +++ head/sys/netinet6/in6_gif.c Sun Jun 7 23:00:40 2009 (r193664) @@ -144,8 +144,22 @@ in6_gif_output(struct ifnet *ifp, #endif case AF_LINK: proto = IPPROTO_ETHERIP; - eiphdr.eip_ver = ETHERIP_VERSION & ETHERIP_VER_VERS_MASK; - eiphdr.eip_pad = 0; + + /* + * GIF_SEND_REVETHIP (disabled by default) intentionally + * sends an EtherIP packet with revered version field in + * the header. This is a knob for backward compatibility + * with FreeBSD 7.2R or prior. + */ + if ((sc->gif_options & GIF_SEND_REVETHIP)) { + eiphdr.eip_ver = 0; + eiphdr.eip_resvl = ETHERIP_VERSION; + eiphdr.eip_resvh = 0; + } else { + eiphdr.eip_ver = ETHERIP_VERSION; + eiphdr.eip_resvl = 0; + eiphdr.eip_resvh = 0; + } /* prepend Ethernet-in-IP header */ M_PREPEND(m, sizeof(struct etherip_header), M_DONTWAIT); if (m && m->m_len < sizeof(struct etherip_header)) Modified: head/sys/sys/priv.h ============================================================================== --- head/sys/sys/priv.h Sun Jun 7 22:55:48 2009 (r193663) +++ head/sys/sys/priv.h Sun Jun 7 23:00:40 2009 (r193664) @@ -324,6 +324,7 @@ #define PRIV_NET_ADDIFADDR 413 /* Add protocol addr to interface. */ #define PRIV_NET_DELIFADDR 414 /* Delete protocol addr on interface. */ #define PRIV_NET_LAGG 415 /* Administer lagg interface. */ +#define PRIV_NET_GIF 416 /* Administer gif interface. */ /* * 802.11-related privileges.