raw ip: fix regression with multicast and RSVP

With 61f7427f02 raw sockets protosw has wildcard pr_protocol.  Protocol
of a specific pcb is stored in inp_ip_p.

Reviewed by:		karels
Reported by:		karels
Differential revision:	https://reviews.freebsd.org/D36429
Fixes:			61f7427f02
This commit is contained in:
Gleb Smirnoff 2022-09-02 12:17:09 -07:00
parent cfdc649e45
commit 74ed2e8ab2
6 changed files with 17 additions and 20 deletions

View File

@ -1313,10 +1313,6 @@ int
ip_rsvp_init(struct socket *so) ip_rsvp_init(struct socket *so)
{ {
if (so->so_type != SOCK_RAW ||
so->so_proto->pr_protocol != IPPROTO_RSVP)
return EOPNOTSUPP;
if (V_ip_rsvpd != NULL) if (V_ip_rsvpd != NULL)
return EADDRINUSE; return EADDRINUSE;

View File

@ -686,11 +686,7 @@ static int
ip_mrouter_init(struct socket *so, int version) ip_mrouter_init(struct socket *so, int version)
{ {
CTR3(KTR_IPMF, "%s: so_type %d, pr_protocol %d", __func__, CTR2(KTR_IPMF, "%s: so %p", __func__, so);
so->so_type, so->so_proto->pr_protocol);
if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_IGMP)
return EOPNOTSUPP;
if (version != 1) if (version != 1)
return ENOPROTOOPT; return ENOPROTOOPT;

View File

@ -693,6 +693,8 @@ rip_ctloutput(struct socket *so, struct sockopt *sopt)
error = priv_check(curthread, PRIV_NETINET_MROUTE); error = priv_check(curthread, PRIV_NETINET_MROUTE);
if (error != 0) if (error != 0)
return (error); return (error);
if (inp->inp_ip_p != IPPROTO_IGMP)
return (EOPNOTSUPP);
error = ip_mrouter_get ? ip_mrouter_get(so, sopt) : error = ip_mrouter_get ? ip_mrouter_get(so, sopt) :
EOPNOTSUPP; EOPNOTSUPP;
break; break;
@ -747,6 +749,8 @@ rip_ctloutput(struct socket *so, struct sockopt *sopt)
error = priv_check(curthread, PRIV_NETINET_MROUTE); error = priv_check(curthread, PRIV_NETINET_MROUTE);
if (error != 0) if (error != 0)
return (error); return (error);
if (inp->inp_ip_p != IPPROTO_RSVP)
return (EOPNOTSUPP);
error = ip_rsvp_init(so); error = ip_rsvp_init(so);
break; break;
@ -762,6 +766,8 @@ rip_ctloutput(struct socket *so, struct sockopt *sopt)
error = priv_check(curthread, PRIV_NETINET_MROUTE); error = priv_check(curthread, PRIV_NETINET_MROUTE);
if (error != 0) if (error != 0)
return (error); return (error);
if (inp->inp_ip_p != IPPROTO_RSVP)
return (EOPNOTSUPP);
error = ip_rsvp_vif ? error = ip_rsvp_vif ?
ip_rsvp_vif(so, sopt) : EINVAL; ip_rsvp_vif(so, sopt) : EINVAL;
break; break;
@ -781,6 +787,8 @@ rip_ctloutput(struct socket *so, struct sockopt *sopt)
error = priv_check(curthread, PRIV_NETINET_MROUTE); error = priv_check(curthread, PRIV_NETINET_MROUTE);
if (error != 0) if (error != 0)
return (error); return (error);
if (inp->inp_ip_p != IPPROTO_IGMP)
return (EOPNOTSUPP);
error = ip_mrouter_set ? ip_mrouter_set(so, sopt) : error = ip_mrouter_set ? ip_mrouter_set(so, sopt) :
EOPNOTSUPP; EOPNOTSUPP;
break; break;

View File

@ -555,12 +555,7 @@ static int
ip6_mrouter_init(struct socket *so, int v, int cmd) ip6_mrouter_init(struct socket *so, int v, int cmd)
{ {
MRT6_DLOG(DEBUG_ANY, "so_type = %d, pr_protocol = %d", MRT6_DLOG(DEBUG_ANY, "%s: socket %p", __func__, so);
so->so_type, so->so_proto->pr_protocol);
if (so->so_type != SOCK_RAW ||
so->so_proto->pr_protocol != IPPROTO_ICMPV6)
return (EOPNOTSUPP);
if (v != 1) if (v != 1)
return (ENOPROTOOPT); return (ENOPROTOOPT);

View File

@ -2451,8 +2451,7 @@ ip6_raw_ctloutput(struct socket *so, struct sockopt *sopt)
* values or -1 as a special value. * values or -1 as a special value.
*/ */
error = EINVAL; error = EINVAL;
} else if (so->so_proto->pr_protocol == } else if (inp->inp_ip_p == IPPROTO_ICMPV6) {
IPPROTO_ICMPV6) {
if (optval != icmp6off) if (optval != icmp6off)
error = EINVAL; error = EINVAL;
} else } else
@ -2460,7 +2459,7 @@ ip6_raw_ctloutput(struct socket *so, struct sockopt *sopt)
break; break;
case SOPT_GET: case SOPT_GET:
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) if (inp->inp_ip_p == IPPROTO_ICMPV6)
optval = icmp6off; optval = icmp6off;
else else
optval = inp->in6p_cksum; optval = inp->in6p_cksum;

View File

@ -596,7 +596,7 @@ rip6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
int int
rip6_ctloutput(struct socket *so, struct sockopt *sopt) rip6_ctloutput(struct socket *so, struct sockopt *sopt)
{ {
struct inpcb *inp; struct inpcb *inp = sotoinpcb(so);
int error; int error;
if (sopt->sopt_level == IPPROTO_ICMPV6) if (sopt->sopt_level == IPPROTO_ICMPV6)
@ -608,7 +608,6 @@ rip6_ctloutput(struct socket *so, struct sockopt *sopt)
else if (sopt->sopt_level != IPPROTO_IPV6) { else if (sopt->sopt_level != IPPROTO_IPV6) {
if (sopt->sopt_level == SOL_SOCKET && if (sopt->sopt_level == SOL_SOCKET &&
sopt->sopt_name == SO_SETFIB) { sopt->sopt_name == SO_SETFIB) {
inp = sotoinpcb(so);
INP_WLOCK(inp); INP_WLOCK(inp);
inp->inp_inc.inc_fibnum = so->so_fibnum; inp->inp_inc.inc_fibnum = so->so_fibnum;
INP_WUNLOCK(inp); INP_WUNLOCK(inp);
@ -629,6 +628,8 @@ rip6_ctloutput(struct socket *so, struct sockopt *sopt)
case MRT6_ADD_MFC: case MRT6_ADD_MFC:
case MRT6_DEL_MFC: case MRT6_DEL_MFC:
case MRT6_PIM: case MRT6_PIM:
if (inp->inp_ip_p != IPPROTO_ICMPV6)
return (EOPNOTSUPP);
error = ip6_mrouter_get ? ip6_mrouter_get(so, sopt) : error = ip6_mrouter_get ? ip6_mrouter_get(so, sopt) :
EOPNOTSUPP; EOPNOTSUPP;
break; break;
@ -650,6 +651,8 @@ rip6_ctloutput(struct socket *so, struct sockopt *sopt)
case MRT6_ADD_MFC: case MRT6_ADD_MFC:
case MRT6_DEL_MFC: case MRT6_DEL_MFC:
case MRT6_PIM: case MRT6_PIM:
if (inp->inp_ip_p != IPPROTO_ICMPV6)
return (EOPNOTSUPP);
error = ip6_mrouter_set ? ip6_mrouter_set(so, sopt) : error = ip6_mrouter_set ? ip6_mrouter_set(so, sopt) :
EOPNOTSUPP; EOPNOTSUPP;
break; break;