From nobody@FreeBSD.org  Thu Jun 26 07:14:00 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 603AB1065681
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jun 2008 07:14:00 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 2D8B28FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jun 2008 07:14:00 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m5Q7DxbH002891
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jun 2008 07:13:59 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m5Q7DxoX002890;
	Thu, 26 Jun 2008 07:13:59 GMT
	(envelope-from nobody)
Message-Id: <200806260713.m5Q7DxoX002890@www.freebsd.org>
Date: Thu, 26 Jun 2008 07:13:59 GMT
From: Shunsuke SHINOMIYA <shino@fornext.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: incorrect EtherIP header format.
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         125003
>Category:       kern
>Synopsis:       [gif] incorrect EtherIP header format.
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    hrs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 26 07:20:05 UTC 2008
>Closed-Date:    Thu Oct 15 07:35:28 UTC 2009
>Last-Modified:  Thu Oct 15 07:35:28 UTC 2009
>Originator:     Shunsuke SHINOMIYA
>Release:        FreeBSD 6.3-RELEASE-p2
>Organization:
>Environment:
FreeBSD dill.fornext.org 6.3-RELEASE-p2 FreeBSD 6.3-RELEASE-p2 #7: Sun May 11 16:14:13 JST 2008     root@dill.fornext.org:/usr/obj/usr/src/sys/VMWARE_FREEBSD6  i386

>Description:
RFC3378 says:
  In summary, the EtherIP Header has two fields:

      Bits 0-3:  Protocol version
      Bits 4-15: Reserved for future use
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:

From: Shunsuke SHINOMIYA <shino@fornext.org>
To: bug-followup@FreeBSD.org,
 shino@fornext.org
Cc:  
Subject: Re: kern/125003: incorrect EtherIP header format.
Date: Thu, 26 Jun 2008 16:49:11 +0900

 Sorry, a part of submitted PR is missing.
 
 Description:
 
 RFC3378 says:
 In summary, the EtherIP Header has two fields:
 
 Bits 0-3: Protocol version
 Bits 4-15: Reserved for future use
 
 But, EtherIP is implemented as follows.
 
 struct etherip_header {
         u_int8_t eip_ver;       /* version/reserved */
         u_int8_t eip_pad;       /* required padding byte */
 };
 
 By this one, FreeBSD box has no interoperability against other EtherIP
 implementations.
 
 Fix:
 
 I modified if_gif.h as follows.
 
 
 > diff -u if_gif.h-1.17.2.2 if_gif.h
 --- if_gif.h-1.17.2.2   2006-02-01 00:56:46.000000000 +0900
 +++ if_gif.h    2008-06-26 15:34:22.000000000 +0900
 @@ -93,8 +93,8 @@
  #define        MTAG_GIF_CALLED 0
 
  struct etherip_header {
 -       u_int8_t eip_ver;       /* version/reserved */
 -       u_int8_t eip_pad;       /* required padding byte */
 +       u_int16_t eip_ver: 4;   /* version/reserved */
 +       u_int16_t eip_pad: 12;  /* required padding byte */
  };
  #define ETHERIP_VER_VERS_MASK   0x0f
  #define ETHERIP_VER_RSVD_MASK   0xf0
 >
 
 -- 
 Shunsuke SHINOMIYA <shino@fornext.org>
 
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Thu Jun 26 13:52:03 UTC 2008 
Responsible-Changed-Why:  
Over to maintainers 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125003 

From: Andrew Thompson <thompsa@FreeBSD.org>
To: Shunsuke SHINOMIYA <shino@fornext.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/125003: incorrect EtherIP header format.
Date: Thu, 26 Jun 2008 07:34:24 -0700

 Hi,
 
 
 It is unclear where the interoperability problem comes in.
 
 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_VERSION         0x03
 
 From rfc3378,
  1. Prepend the 16-bit EtherIP header to the MAC frame.  The EtherIP
     Version field MUST be set to 3 (three), and the EtherIP Reserved
     field MUST be set to 0 (zero).
 
 
 And the outgoing header is set to.
    eiphdr.eip_ver = ETHERIP_VERSION & ETHERIP_VER_VERS_MASK;
    eiphdr.eip_pad = 0;
 
 Which would conform to the requirement. Can you describe the problem you
 are seeing.
 
 
 regards,
 Andrew

From: Hiroki Sato <hrs@FreeBSD.org>
To: shino@fornext.org
Cc: freebsd-bugs@FreeBSD.org, bug-followup@FreeBSD.org
Subject: Re: kern/125003: incorrect EtherIP header format.
Date: Fri, 27 Jun 2008 00:30:14 +0900 (JST)

 ----Security_Multipart(Fri_Jun_27_00_30_14_2008_807)--
 Content-Type: Text/Plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 Shunsuke SHINOMIYA <shino@fornext.org> wrote
   in <20080626192225.9813.A2D40D1E@fornext.org>:
 
 sh>  In current implementation, 0x03 is transmitted, and, next, 0x00 is
 sh>  transmitted as version(3) and reserved(0x000) field. But I think that
 sh>  0x30 should be transmitted first from RFC3378.
 
  I don't understand why you think 0x30 is correct.
 
 --
 | Hiroki SATO
 
 ----Security_Multipart(Fri_Jun_27_00_30_14_2008_807)--
 Content-Type: application/pgp-signature
 Content-Transfer-Encoding: 7bit
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.9 (FreeBSD)
 
 iEYEABECAAYFAkhjtgYACgkQTyzT2CeTzy21ZQCfa0YYRixI0Sq5yb779GTsTtOX
 9z0AoIdkDi+H/h2pSB30vTvZk60OwXIM
 =0Fi9
 -----END PGP SIGNATURE-----
 
 ----Security_Multipart(Fri_Jun_27_00_30_14_2008_807)----

From: Shunsuke SHINOMIYA <shino@fornext.org>
To: Hiroki Sato <hrs@FreeBSD.org>
Cc: freebsd-bugs@FreeBSD.org,
 bug-followup@FreeBSD.org
Subject: Re[2]: kern/125003: incorrect EtherIP header format.
Date: Fri, 27 Jun 2008 15:00:45 +0900

 > sh>  In current implementation, 0x03 is transmitted, and, next, 0x00 is
 > sh>  transmitted as version(3) and reserved(0x000) field. But I think tha=
 t
 > sh>  0x30 should be transmitted first from RFC3378.
 >=20
 >  I don't understand why you think 0x30 is correct.
 
 =46rom RFC3378
 > In summary, the EtherIP Header has two fields:
 >=20
 >       Bits 0-3:  Protocol version
 >       Bits 4-15: Reserved for future use
 >=20
 >         0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
 >      +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
 >      |               |                                               |
 >      |    VERSION    |                   RESERVED                    |
 >      |               |                                               |
 >      +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
 >=20
 >                  Figure 2: EtherIP Header Format (in bits)
 >=20
 
 , first octet(bit 0,MSB to 7) consists of VERSION and a part of RESERVED.
 And VERSION is high 4 bits of the octet.
 Am I misunderstanding this?
 
 --=20
 Shunsuke SHINOMIYA <shino@fornext.org>
 

From: Hiroki Sato <hrs@FreeBSD.org>
To: shino@fornext.org
Cc: freebsd-bugs@FreeBSD.org, bug-followup@FreeBSD.org
Subject: Re: kern/125003: incorrect EtherIP header format.
Date: Sun, 29 Jun 2008 01:35:12 +0900 (JST)

 ----Security_Multipart(Sun_Jun_29_01_35_12_2008_272)--
 Content-Type: Text/Plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 Shunsuke SHINOMIYA <shino@fornext.org> wrote
   in <200806270610.m5R6A3hR060682@freefall.freebsd.org>:
 
 sh>  =46rom RFC3378
 sh>  > In summary, the EtherIP Header has two fields:
 sh>  >=20
 sh>  >       Bits 0-3:  Protocol version
 sh>  >       Bits 4-15: Reserved for future use
 sh>  >=20
 sh>  >         0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
 sh>  >      +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
 sh>  >      |               |                                               |
 sh>  >      |    VERSION    |                   RESERVED                    |
 sh>  >      |               |                                               |
 sh>  >      +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
 sh>  >=20
 sh>  >                  Figure 2: EtherIP Header Format (in bits)
 sh>  >=20
 sh>
 sh>  , first octet(bit 0,MSB to 7) consists of VERSION and a part of RESERVED.
 sh>  And VERSION is high 4 bits of the octet.
 sh>  Am I misunderstanding this?
 
  The VERSION is in bit 0-3 and LSB in this diagram is left.  As Andrew
  also explained, these are the reasons why ETHERIP_VER_VERS_MASK is
  defined as 0x0f.
 
  Do you really have interoperability problem?  If so, please let us
  know more detail information about it first.
 
 --
 | Hiroki SATO
 
 ----Security_Multipart(Sun_Jun_29_01_35_12_2008_272)--
 Content-Type: application/pgp-signature
 Content-Transfer-Encoding: 7bit
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.9 (FreeBSD)
 
 iEYEABECAAYFAkhmaEAACgkQTyzT2CeTzy12bwCfTQ2kE20quy6BU+vd9wYaNwS+
 cxQAnA8yh2VRKHuRcxLZc459791hXOFY
 =a1zs
 -----END PGP SIGNATURE-----
 
 ----Security_Multipart(Sun_Jun_29_01_35_12_2008_272)----
State-Changed-From-To: open->feedback 
State-Changed-By: hrs 
State-Changed-When: Sat Jun 28 18:57:46 UTC 2008 
State-Changed-Why:  
We need a detail about this issue from the PR originator. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125003 

From: Shunsuke SHINOMIYA <shino@fornext.org>
To: Andrew Thompson <thompsa@FreeBSD.org>,
 Hiroki Sato <hrs@FreeBSD.org>
Cc: freebsd-bugs@FreeBSD.org,
 bug-followup@FreeBSD.org
Subject: Re[2]: kern/125003: incorrect EtherIP header format.
Date: Sun, 29 Jun 2008 16:27:33 +0900

 Hi,
 
 > It is unclear where the interoperability problem comes in.
 
 I'm sorry. A fix I submitted was a mistake.
 
 
 > Which would conform to the requirement. Can you describe the problem you
 > are seeing.
 
  FreeBSD's current implementation expects 0x03, 0x00 as EtherIP header,
  but another implementation(UNIVERGE IX2015, products by NEC, Japan)
  transmits 0x30, 0x00. Then FreeBSD box discards EtherIP packets.
 
  I read RFC3378 and thought 0x30, 0x00 is correct.
 
 
 The result of 'tcpdump -np -x proto etherip' at FreeBSD box is as
 follows.
 
 192.168.2.37: FreeBSD box
 192.168.2.128: IX2015
 MAC addresses were replaced with ****.
 
 16:02:40.952832 IP 192.168.2.128 > 192.168.2.37:  etherip 344
         0x0000:  4500 016c 0098 0000 4061 f2a3 c0a8 0280
         0x0010:  c0a8 0225 3000 **** **** **** **** ****
                            ~~~~ EtherIP header by IX2015
 snip
 
 16:02:48.080826 IP 192.168.2.37 > 192.168.2.128:  etherip 108
         0x0000:  4500 0080 01f3 0000 1e61 1435 c0a8 0225
         0x0010:  c0a8 0280 0300 **** **** **** **** ****
                            ~~~~ EtherIP header by FreeBSD
 snip
 
 -- 
 Shunsuke SHINOMIYA <shino@fornext.org>
 
State-Changed-From-To: feedback->open 
State-Changed-By: hrs 
State-Changed-When: Sun Jun 29 08:21:04 UTC 2008 
State-Changed-Why:  
We have a concrete case now. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125003 

From: Hiroki Sato <hrs@FreeBSD.org>
To: shino@fornext.org
Cc: thompsa@FreeBSD.org, freebsd-bugs@FreeBSD.org, bug-followup@FreeBSD.org,
        hrs@FreeBSD.org
Subject: Re: kern/125003: incorrect EtherIP header format.
Date: Sun, 29 Jun 2008 18:57:11 +0900 (JST)

 ----Security_Multipart(Sun_Jun_29_18_57_11_2008_878)--
 Content-Type: Text/Plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 Shunsuke SHINOMIYA <shino@fornext.org> wrote
   in <20080629150108.6783.A2D40D1E@fornext.org>:
 
 sh>  FreeBSD's current implementation expects 0x03, 0x00 as EtherIP header,
 sh>  but another implementation(UNIVERGE IX2015, products by NEC, Japan)
 sh>  transmits 0x30, 0x00. Then FreeBSD box discards EtherIP packets.
 
  Could you let me know if the following patch solves your symptom or
  not?  It can be applied to 8.x and 7.x:
 
  http://people.allbsd.org/~hrs/FreeBSD/gif.diff
 
 --
 | Hiroki SATO
 
 ----Security_Multipart(Sun_Jun_29_18_57_11_2008_878)--
 Content-Type: application/pgp-signature
 Content-Transfer-Encoding: 7bit
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.9 (FreeBSD)
 
 iEYEABECAAYFAkhnXHcACgkQTyzT2CeTzy1/SgCgueGgx06kNVVrgyR5Ryf2K+0I
 XJ0AnRbtkaW72joKYjyqGF/jVkKeRWAm
 =IsCy
 -----END PGP SIGNATURE-----
 
 ----Security_Multipart(Sun_Jun_29_18_57_11_2008_878)----

From: Shunsuke SHINOMIYA <shino@fornext.org>
To: Hiroki Sato <hrs@FreeBSD.org>
Cc: thompsa@FreeBSD.org,
 freebsd-bugs@FreeBSD.org,
 bug-followup@FreeBSD.org
Subject: Re[2]: kern/125003: incorrect EtherIP header format.
Date: Sun, 29 Jun 2008 20:38:51 +0900

 --------_4867660B00000000A846_MULTIPART_MIXED_
 Content-Type: text/plain; charset="US-ASCII"
 Content-Transfer-Encoding: 7bit
 
 
 Hi,
 
 >  Could you let me know if the following patch solves your symptom or
 >  not?  It can be applied to 8.x and 7.x:
 > 
 >  http://people.allbsd.org/~hrs/FreeBSD/gif.diff
 
  Thank you.
 
  I applied your patch to RELENG_6_3 and modified netinet6/in6_gif.c
  manually(because of tab expansion?).
 
  I had 2 problems.
  One is syntax error around `eip_ver:4,' when BYTE_ORDER is LITTELE_ENDIAN.
  
  Another one is 2 octet padding for struct etherip_header. To solve this,
  I specified __packed attribute for this structure.
 
  Attached patch based on yours is for RELENG_6_3.
 
 Patched implementation works well with IX2015.
 
 192.168.2.37: FreeBSD box
 192.168.2.128: IX2015
 
 20:22:55.540804 IP 192.168.2.128 > 192.168.2.37:  etherip 76
         0x0000:  4500 0060 076b 0000 4061 ecdc c0a8 0280
         0x0010:  c0a8 0225 3000 **** **** **** **** ****
         0x0020:  **** 0800 4500 003c 0cc0 0000 8001 a82e
         0x0030:  c0a8 0281 c0a8 0201 0800 4753 0001 0608
         0x0040:  6162 6364 6566 6768 696a 6b6c 6d6e 6f70
         0x0050:  7172
 20:22:55.541815 IP 192.168.2.37 > 192.168.2.128:  etherip 76
         0x0000:  4500 0060 3511 0000 1e61 e136 c0a8 0225
         0x0010:  c0a8 0280 3000 **** **** **** **** ****
         0x0020:  **** 0800 4500 003c 319b 0000 4001 c353
         0x0030:  c0a8 0201 c0a8 0281 0000 4f53 0001 0608
         0x0040:  6162 6364 6566 6768 696a 6b6c 6d6e 6f70
         0x0050:  7172
 
 -- 
 Shunsuke SHINOMIYA <shino@fornext.org>
 
 --------_4867660B00000000A846_MULTIPART_MIXED_
 Content-Type: application/octet-stream;
  name="gif6.diff"
 Content-Disposition: attachment;
  filename="gif6.diff"
 Content-Transfer-Encoding: base64
 
 LS0tIG5ldC9pZl9naWYuaC5vcmlnCTIwMDYtMDItMDEgMDA6NTY6NDYuMDAwMDAwMDAwICswOTAw
 CisrKyBuZXQvaWZfZ2lmLmgJMjAwOC0wNi0yOSAxOTozNjo0MC4wMDAwMDAwMDAgKzA5MDAKQEAg
 LTkzLDEyICs5MywxNyBAQAogI2RlZmluZQlNVEFHX0dJRl9DQUxMRUQJMAogCiBzdHJ1Y3QgZXRo
 ZXJpcF9oZWFkZXIgewotCXVfaW50OF90IGVpcF92ZXI7CS8qIHZlcnNpb24vcmVzZXJ2ZWQgKi8K
 LQl1X2ludDhfdCBlaXBfcGFkOwkvKiByZXF1aX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 cikpCg==
 --------_4867660B00000000A846_MULTIPART_MIXED_--
 
Responsible-Changed-From-To: freebsd-net->hrs 
Responsible-Changed-By: hrs 
Responsible-Changed-When: Thu Jul 17 21:47:32 UTC 2008 
Responsible-Changed-Why:  
I will handle this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125003 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/125003: commit references a PR
Date: Sun,  7 Jun 2009 23:00:53 +0000 (UTC)

 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 <sys/param.h>
 +#include <sys/ioctl.h>
 +#include <sys/socket.h>
 +#include <sys/sockio.h>
 +
 +#include <stdlib.h>
 +#include <unistd.h>
 +
 +#include <net/ethernet.h>
 +#include <net/if.h>
 +#include <net/if_gif.h>
 +#include <net/route.h>
 +
 +#include <ctype.h>
 +#include <stdio.h>
 +#include <string.h>
 +#include <stdlib.h>
 +#include <unistd.h>
 +#include <err.h>
 +#include <errno.h>
 +
 +#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 <sys/time.h>
  #include <sys/sysctl.h>
  #include <sys/syslog.h>
 +#include <sys/priv.h>
  #include <sys/proc.h>
  #include <sys/protosw.h>
  #include <sys/conf.h>
 @@ -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.
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: hrs 
State-Changed-When: Sun Jun 7 23:39:21 UTC 2009 
State-Changed-Why:  
Sorry for the long delay.  Fixed on -CURRENT now and will be merged to 
6.x and 7.x.  If you notice something wrong, please let me know. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125003 
State-Changed-From-To: patched->closed 
State-Changed-By: hrs 
State-Changed-When: Thu Oct 15 07:34:24 UTC 2009 
State-Changed-Why:  
Merged to STABLE.  Thanks for the report! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125003 
>Unformatted:
