- Remove GIF_{SEND,ACCEPT}_REVETHIP.

- Simplify EADDRNOTAVAIL and EAFNOSUPPORT conditions.

MFC after:	3 days
This commit is contained in:
Hiroki Sato 2015-09-10 05:59:39 +00:00
parent 32766cd281
commit b1c250ff3f
4 changed files with 29 additions and 96 deletions

View File

@ -51,7 +51,7 @@ static const char rcsid[] =
#include "ifconfig.h"
#define GIFBITS "\020\1ACCEPT_REV_ETHIP_VER\2IGNORE_SOURCE\5SEND_REV_ETHIP_VER"
#define GIFBITS "\020\2IGNORE_SOURCE"
static void gif_status(int);
@ -70,8 +70,7 @@ gif_status(int s)
}
static void
setgifopts(const char *val,
int d, int s, const struct afswtch *afp)
setgifopts(const char *val, int d, int s, const struct afswtch *afp)
{
int opts;
@ -93,12 +92,8 @@ setgifopts(const char *val,
}
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("ignore_source", GIF_IGNORE_SOURCE, setgifopts),
DEF_CMD("-ignore_source", -GIF_IGNORE_SOURCE, 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 = {
@ -110,11 +105,9 @@ static struct afswtch af_gif = {
static __constructor void
gif_ctor(void)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
size_t i;
for (i = 0; i < N(gif_cmds); i++)
for (i = 0; i < nitems(gif_cmds); i++)
cmd_register(&gif_cmds[i]);
af_register(&af_gif);
#undef N
}

View File

@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd October 14, 2014
.Dd September 10, 2015
.Dt GIF 4
.Os
.Sh NAME
@ -246,32 +246,3 @@ had a multi-destination behavior, configurable via
.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.

View File

@ -421,13 +421,8 @@ gif_transmit(struct ifnet *ifp, struct mbuf *m)
}
eth = mtod(m, struct etherip_header *);
eth->eip_resvh = 0;
if ((sc->gif_options & GIF_SEND_REVETHIP) != 0) {
eth->eip_ver = 0;
eth->eip_resvl = ETHERIP_VERSION;
} else {
eth->eip_ver = ETHERIP_VERSION;
eth->eip_resvl = 0;
}
eth->eip_ver = ETHERIP_VERSION;
eth->eip_resvl = 0;
break;
default:
error = EAFNOSUPPORT;
@ -635,19 +630,10 @@ gif_input(struct mbuf *m, struct ifnet *ifp, int proto, uint8_t ecn)
if (m == NULL)
goto drop;
eip = mtod(m, struct etherip_header *);
/*
* 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 (eip->eip_ver != ETHERIP_VERSION) {
if ((gif_options & GIF_ACCEPT_REVETHIP) == 0 ||
eip->eip_resvl != ETHERIP_VERSION) {
/* discard unknown versions */
m_freem(m);
goto drop;
}
/* discard unknown versions */
m_freem(m);
goto drop;
}
m_adj(m, sizeof(struct etherip_header));
@ -768,50 +754,32 @@ gif_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
goto bad;
/* validate sa_len */
/* check sa_family looks sane for the cmd */
switch (src->sa_family) {
#ifdef INET
case AF_INET:
if (src->sa_len != sizeof(struct sockaddr_in))
goto bad;
if (cmd != SIOCSIFPHYADDR) {
error = EAFNOSUPPORT;
goto bad;
}
if (satosin(src)->sin_addr.s_addr == INADDR_ANY ||
satosin(dst)->sin_addr.s_addr == INADDR_ANY) {
error = EADDRNOTAVAIL;
goto bad;
}
break;
#endif
#ifdef INET6
case AF_INET6:
if (src->sa_len != sizeof(struct sockaddr_in6))
goto bad;
break;
#endif
default:
error = EAFNOSUPPORT;
goto bad;
}
/* check sa_family looks sane for the cmd */
error = EAFNOSUPPORT;
switch (cmd) {
#ifdef INET
case SIOCSIFPHYADDR:
if (src->sa_family == AF_INET)
break;
goto bad;
#endif
#ifdef INET6
case SIOCSIFPHYADDR_IN6:
if (src->sa_family == AF_INET6)
break;
goto bad;
#endif
}
error = EADDRNOTAVAIL;
switch (src->sa_family) {
#ifdef INET
case AF_INET:
if (satosin(src)->sin_addr.s_addr == INADDR_ANY ||
satosin(dst)->sin_addr.s_addr == INADDR_ANY)
if (cmd != SIOCSIFPHYADDR_IN6) {
error = EAFNOSUPPORT;
goto bad;
break;
#endif
#ifdef INET6
case AF_INET6:
}
error = EADDRNOTAVAIL;
if (IN6_IS_ADDR_UNSPECIFIED(&satosin6(src)->sin6_addr)
||
IN6_IS_ADDR_UNSPECIFIED(&satosin6(dst)->sin6_addr))
@ -827,8 +795,12 @@ gif_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
error = sa6_embedscope(satosin6(dst), 0);
if (error != 0)
goto bad;
break;
#endif
};
default:
error = EAFNOSUPPORT;
goto bad;
}
error = gif_set_tunnel(ifp, src, dst);
break;
case SIOCDIFPHYADDR:

View File

@ -126,10 +126,7 @@ int in6_gif_attach(struct gif_softc *);
#define GIFGOPTS _IOWR('i', 150, struct ifreq)
#define GIFSOPTS _IOW('i', 151, struct ifreq)
#define GIF_ACCEPT_REVETHIP 0x0001
#define GIF_IGNORE_SOURCE 0x0002
#define GIF_SEND_REVETHIP 0x0010
#define GIF_OPTMASK (GIF_ACCEPT_REVETHIP|GIF_SEND_REVETHIP| \
GIF_IGNORE_SOURCE)
#define GIF_OPTMASK (GIF_IGNORE_SOURCE)
#endif /* _NET_IF_GIF_H_ */