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)
{
if (so->so_type != SOCK_RAW ||
so->so_proto->pr_protocol != IPPROTO_RSVP)
return EOPNOTSUPP;
if (V_ip_rsvpd != NULL)
return EADDRINUSE;

View File

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

View File

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

View File

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

View File

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

View File

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