diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2005-01-11 08:57:25 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2005-01-11 08:57:25 +0000 |
commit | 0322878bb288abe3775201323113c3b7a76a7b9c (patch) | |
tree | 6a4862626470889498a2c8779c1a9e5560655ee6 /sys/netinet6 | |
parent | 655efca035601d1087a76d3d52ba1bcf94efa63e (diff) |
correctly deal with unspecified (zero) interface number in IPV6_MULTICAST_IF,
IPV6_{JOIN,LEAVE}_GROUP ioctls; ok itojun@
Diffstat (limited to 'sys/netinet6')
-rw-r--r-- | sys/netinet6/ip6_output.c | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index b6e2e63fa4e..9a55e90007d 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_output.c,v 1.86 2004/06/21 19:26:02 mcbride Exp $ */ +/* $OpenBSD: ip6_output.c,v 1.87 2005/01/11 08:57:24 djm Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* @@ -1863,15 +1863,20 @@ ip6_setmoptions(optname, im6op, m) break; } bcopy(mtod(m, u_int *), &ifindex, sizeof(ifindex)); - if (ifindex < 0 || if_indexlim <= ifindex || - !ifindex2ifnet[ifindex]) { - error = ENXIO; /* XXX EINVAL? */ - break; - } - ifp = ifindex2ifnet[ifindex]; - if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) { - error = EADDRNOTAVAIL; - break; + if (ifindex == 0) + ifp = NULL; + else { + if (ifindex < 0 || if_indexlim <= ifindex || + !ifindex2ifnet[ifindex]) { + error = ENXIO; /* XXX EINVAL? */ + break; + } + ifp = ifindex2ifnet[ifindex]; + if (ifp == NULL || + (ifp->if_flags & IFF_MULTICAST) == 0) { + error = EADDRNOTAVAIL; + break; + } } im6o->im6o_multicast_ifp = ifp; break; @@ -1940,15 +1945,6 @@ ip6_setmoptions(optname, im6op, m) } /* - * If the interface is specified, validate it. - */ - if (mreq->ipv6mr_interface < 0 || - if_indexlim <= mreq->ipv6mr_interface || - !ifindex2ifnet[mreq->ipv6mr_interface]) { - error = ENXIO; /* XXX EINVAL? */ - break; - } - /* * If no interface was explicitly specified, choose an * appropriate one according to the given multicast address. */ @@ -1977,8 +1973,18 @@ ip6_setmoptions(optname, im6op, m) ifp = ro.ro_rt->rt_ifp; rtfree(ro.ro_rt); } - } else + } else { + /* + * If the interface is specified, validate it. + */ + if (mreq->ipv6mr_interface < 0 || + if_indexlim <= mreq->ipv6mr_interface || + !ifindex2ifnet[mreq->ipv6mr_interface]) { + error = ENXIO; /* XXX EINVAL? */ + break; + } ifp = ifindex2ifnet[mreq->ipv6mr_interface]; + } /* * See if we found an interface, and confirm that it @@ -2043,13 +2049,18 @@ ip6_setmoptions(optname, im6op, m) * If an interface address was specified, get a pointer * to its ifnet structure. */ - if (mreq->ipv6mr_interface < 0 || - if_indexlim <= mreq->ipv6mr_interface || - !ifindex2ifnet[mreq->ipv6mr_interface]) { - error = ENXIO; /* XXX EINVAL? */ - break; + if (mreq->ipv6mr_interface == 0) + ifp = NULL; + else { + if (mreq->ipv6mr_interface < 0 || + if_indexlim <= mreq->ipv6mr_interface || + !ifindex2ifnet[mreq->ipv6mr_interface]) { + error = ENXIO; /* XXX EINVAL? */ + break; + } + ifp = ifindex2ifnet[mreq->ipv6mr_interface]; } - ifp = ifindex2ifnet[mreq->ipv6mr_interface]; + /* * Put interface index into the multicast address, * if the address has link-local scope. |