Add SO_SETFIB option support on PF_INET6 sockets and allow inheriting the
FIB number from the process, as set by setfib(2), on socket creation. Sponsored by: Cisco Systems, Inc.
This commit is contained in:
parent
096f27864f
commit
ee799639e8
@ -392,6 +392,7 @@ socreate(int dom, struct socket **aso, int type, int proto,
|
||||
so->so_type = type;
|
||||
so->so_cred = crhold(cred);
|
||||
if ((prp->pr_domain->dom_family == PF_INET) ||
|
||||
(prp->pr_domain->dom_family == PF_INET6) ||
|
||||
(prp->pr_domain->dom_family == PF_ROUTE))
|
||||
so->so_fibnum = td->td_proc->p_fibnum;
|
||||
else
|
||||
@ -2498,12 +2499,13 @@ sosetopt(struct socket *so, struct sockopt *sopt)
|
||||
case SO_SETFIB:
|
||||
error = sooptcopyin(sopt, &optval, sizeof optval,
|
||||
sizeof optval);
|
||||
if (optval < 0 || optval > rt_numfibs) {
|
||||
if (optval < 0 || optval >= rt_numfibs) {
|
||||
error = EINVAL;
|
||||
goto bad;
|
||||
}
|
||||
if (so->so_proto != NULL &&
|
||||
((so->so_proto->pr_domain->dom_family == PF_INET) ||
|
||||
(so->so_proto->pr_domain->dom_family == PF_INET6) ||
|
||||
(so->so_proto->pr_domain->dom_family == PF_ROUTE))) {
|
||||
so->so_fibnum = optval;
|
||||
/* Note: ignore error */
|
||||
|
@ -1448,6 +1448,12 @@ ip6_ctloutput(struct socket *so, struct sockopt *sopt)
|
||||
INP_WUNLOCK(in6p);
|
||||
error = 0;
|
||||
break;
|
||||
case SO_SETFIB:
|
||||
INP_WLOCK(in6p);
|
||||
in6p->inp_inc.inc_fibnum = so->so_fibnum;
|
||||
INP_WUNLOCK(in6p);
|
||||
error = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -582,6 +582,7 @@ rip6_output(m, va_alist)
|
||||
int
|
||||
rip6_ctloutput(struct socket *so, struct sockopt *sopt)
|
||||
{
|
||||
struct inpcb *inp;
|
||||
int error;
|
||||
|
||||
if (sopt->sopt_level == IPPROTO_ICMPV6)
|
||||
@ -590,8 +591,17 @@ rip6_ctloutput(struct socket *so, struct sockopt *sopt)
|
||||
* from protosw?
|
||||
*/
|
||||
return (icmp6_ctloutput(so, sopt));
|
||||
else if (sopt->sopt_level != IPPROTO_IPV6)
|
||||
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);
|
||||
return (0);
|
||||
}
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
error = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user