FreeBSD/sys/netinet/raw_ip.c
/*
 * Raw IP socket option processing.
 *
 * IMPORTANT NOTE regarding access control: Traditionally, raw sockets could
 * only be created by a privileged process, and as such, socket option
 * operations to manage system properties on any raw socket were allowed to
 * take place without explicit additional access control checks.  However,
 * raw sockets can now also be created in jail(), and therefore explicit
 * checks are now required.  Likewise, raw sockets can be used by a process
 * after it gives up privilege, so some caution is required.  For options
 * passed down to the IP layer via ip_ctloutput(), checks are assumed to be
 * performed in ip_ctloutput() and therefore no check occurs here.
 * Unilaterally checking priv_check() here breaks normal IP socket option
 * operations on raw sockets.
 *
 * When adding new socket options here, make sure to add access control
 * checks here as necessary.
 *
 * XXX-BZ inp locking?
 */
Raw IP socket option processing.
IMPORTANT NOTE regarding access control: Traditionally, raw sockets could
only be created by a privileged process, and as such, socket option
operations to manage system properties on any raw socket were allowed to
take place without explicit additional access control checks.  However,
raw sockets can now also be created in jail(), and therefore explicit
checks are now required.  Likewise, raw sockets can be used by a process
after it gives up privilege, so some caution is required.  For options
passed down to the IP layer via ip_ctloutput(), checks are assumed to be
performed in ip_ctloutput() and therefore no check occurs here.
Unilaterally checking priv_check() here breaks normal IP socket option
operations on raw sockets.

When adding new socket options here, make sure to add access control
checks here as necessary.


Raw IP socket option processing . IMPORTANT NOTE regarding access control : Traditionally raw sockets could only be created by a privileged process and as such socket option operations to manage system properties on any raw socket were allowed to take place without explicit additional access control checks . However raw sockets can now also be created in jail () and therefore explicit checks are now required . Likewise raw sockets can be used by a process after it gives up privilege so some caution is required . For options passed down to the IP layer via ip_ctloutput () checks are assumed to be performed in ip_ctloutput () and therefore no check occurs here . Unilaterally checking priv_check () here breaks normal IP socket option operations on raw sockets . When adding new socket options here make sure to add access control checks here as necessary .
int
rip_ctloutput(struct socket *so, struct sockopt *sopt)
{
	struct	inpcb *inp = sotoinpcb(so);
	int	error, optval;
	if (sopt->sopt_level != IPPROTO_IP) {
		if ((sopt->sopt_level == SOL_SOCKET) &&
		    (sopt->sopt_name == SO_SETFIB)) {
			inp->inp_inc.inc_fibnum = so->so_fibnum;
			return (0);
		}
		return (EINVAL);
	}
	error = 0;
	switch (sopt->sopt_dir) {
	case SOPT_GET:
		switch (sopt->sopt_name) {
		case IP_HDRINCL:
			optval = inp->inp_flags & INP_HDRINCL;
			error = sooptcopyout(sopt, &optval, sizeof optval);
			break;
		case IP_FW3:	
		case IP_FW_ADD:	
		case IP_FW_GET:
		case IP_FW_TABLE_GETSIZE:
		case IP_FW_TABLE_LIST:
		case IP_FW_NAT_GET_CONFIG:
		case IP_FW_NAT_GET_LOG:
			if (V_ip_fw_ctl_ptr != NULL)
				error = V_ip_fw_ctl_ptr(sopt);
			else
				error = ENOPROTOOPT;
			break;
		case IP_DUMMYNET3:	
		case IP_DUMMYNET_GET:
			if (ip_dn_ctl_ptr != NULL)
				error = ip_dn_ctl_ptr(sopt);
			else
				error = ENOPROTOOPT;
			break ;
		case MRT_INIT:
		case MRT_DONE:
		case MRT_ADD_VIF:
		case MRT_DEL_VIF:
		case MRT_ADD_MFC:
		case MRT_DEL_MFC:
		case MRT_VERSION:
		case MRT_ASSERT:
		case MRT_API_SUPPORT:
		case MRT_API_CONFIG:
		case MRT_ADD_BW_UPCALL:
		case MRT_DEL_BW_UPCALL:
			error = priv_check(curthread, PRIV_NETINET_MROUTE);
			if (error != 0)
				return (error);
			error = ip_mrouter_get ? ip_mrouter_get(so, sopt) :
				EOPNOTSUPP;
			break;
		default:
			error = ip_ctloutput(so, sopt);
			break;
		}
		break;
	case SOPT_SET:
		switch (sopt->sopt_name) {
		case IP_HDRINCL:
			error = sooptcopyin(sopt, &optval, sizeof optval,
					    sizeof optval);
			if (error)
				break;
			if (optval)
				inp->inp_flags |= INP_HDRINCL;
			else
				inp->inp_flags &= ~INP_HDRINCL;
			break;
		case IP_FW3:	
		case IP_FW_ADD:
		case IP_FW_DEL:
		case IP_FW_FLUSH:
		case IP_FW_ZERO:
		case IP_FW_RESETLOG:
		case IP_FW_TABLE_ADD:
		case IP_FW_TABLE_DEL:
		case IP_FW_TABLE_FLUSH:
		case IP_FW_NAT_CFG:
		case IP_FW_NAT_DEL:
			if (V_ip_fw_ctl_ptr != NULL)
				error = V_ip_fw_ctl_ptr(sopt);
			else
				error = ENOPROTOOPT;
			break;
		case IP_DUMMYNET3:	
		case IP_DUMMYNET_CONFIGURE:
		case IP_DUMMYNET_DEL:
		case IP_DUMMYNET_FLUSH:
			if (ip_dn_ctl_ptr != NULL)
				error = ip_dn_ctl_ptr(sopt);
			else
				error = ENOPROTOOPT ;
			break ;
		case IP_RSVP_ON:
			error = priv_check(curthread, PRIV_NETINET_MROUTE);
			if (error != 0)
				return (error);
			error = ip_rsvp_init(so);
			break;
		case IP_RSVP_OFF:
			error = priv_check(curthread, PRIV_NETINET_MROUTE);
			if (error != 0)
				return (error);
			error = ip_rsvp_done();
			break;
		case IP_RSVP_VIF_ON:
		case IP_RSVP_VIF_OFF:
			error = priv_check(curthread, PRIV_NETINET_MROUTE);
			if (error != 0)
				return (error);
			error = ip_rsvp_vif ?
				ip_rsvp_vif(so, sopt) : EINVAL;
			break;
		case MRT_INIT:
		case MRT_DONE:
		case MRT_ADD_VIF:
		case MRT_DEL_VIF:
		case MRT_ADD_MFC:
		case MRT_DEL_MFC:
		case MRT_VERSION:
		case MRT_ASSERT:
		case MRT_API_SUPPORT:
		case MRT_API_CONFIG:
		case MRT_ADD_BW_UPCALL:
		case MRT_DEL_BW_UPCALL:
			error = priv_check(curthread, PRIV_NETINET_MROUTE);
			if (error != 0)
				return (error);
			error = ip_mrouter_set ? ip_mrouter_set(so, sopt) :
					EOPNOTSUPP;
			break;
		default:
			error = ip_ctloutput(so, sopt);
			break;
		}
		break;
	}
	return (error);
}
int rip_ctloutput ( struct socket * so , struct sockopt * sopt ) { struct inpcb * inp = sotoinpcb ( so ) ; int error , optval ; if ( sopt -> sopt_level != IPPROTO_IP ) { if ( ( sopt -> sopt_level == SOL_SOCKET ) && ( sopt -> sopt_name == SO_SETFIB ) ) { inp -> inp_inc . inc_fibnum = so -> so_fibnum ; return ( 0 ) ; } return ( EINVAL ) ; } error = 0 ; switch ( sopt -> sopt_dir ) { case SOPT_GET : switch ( sopt -> sopt_name ) { case IP_HDRINCL : optval = inp -> inp_flags & INP_HDRINCL ; error = sooptcopyout ( sopt , & optval , sizeof optval ) ; break ; case IP_FW3 : case IP_FW_ADD : case IP_FW_GET : case IP_FW_TABLE_GETSIZE : case IP_FW_TABLE_LIST : case IP_FW_NAT_GET_CONFIG : case IP_FW_NAT_GET_LOG : if ( V_ip_fw_ctl_ptr != NULL ) error = V_ip_fw_ctl_ptr ( sopt ) ; else error = ENOPROTOOPT ; break ; case IP_DUMMYNET3 : case IP_DUMMYNET_GET : if ( ip_dn_ctl_ptr != NULL ) error = ip_dn_ctl_ptr ( sopt ) ; else error = ENOPROTOOPT ; break ; case MRT_INIT : case MRT_DONE : case MRT_ADD_VIF : case MRT_DEL_VIF : case MRT_ADD_MFC : case MRT_DEL_MFC : case MRT_VERSION : case MRT_ASSERT : case MRT_API_SUPPORT : case MRT_API_CONFIG : case MRT_ADD_BW_UPCALL : case MRT_DEL_BW_UPCALL : error = priv_check ( curthread , PRIV_NETINET_MROUTE ) ; if ( error != 0 ) return ( error ) ; error = ip_mrouter_get ? ip_mrouter_get ( so , sopt ) : EOPNOTSUPP ; break ; default : error = ip_ctloutput ( so , sopt ) ; break ; } break ; case SOPT_SET : switch ( sopt -> sopt_name ) { case IP_HDRINCL : error = sooptcopyin ( sopt , & optval , sizeof optval , sizeof optval ) ; if ( error ) break ; if ( optval ) inp -> inp_flags |= INP_HDRINCL ; else inp -> inp_flags &= ~ INP_HDRINCL ; break ; case IP_FW3 : case IP_FW_ADD : case IP_FW_DEL : case IP_FW_FLUSH : case IP_FW_ZERO : case IP_FW_RESETLOG : case IP_FW_TABLE_ADD : case IP_FW_TABLE_DEL : case IP_FW_TABLE_FLUSH : case IP_FW_NAT_CFG : case IP_FW_NAT_DEL : if ( V_ip_fw_ctl_ptr != NULL ) error = V_ip_fw_ctl_ptr ( sopt ) ; else error = ENOPROTOOPT ; break ; case IP_DUMMYNET3 : case IP_DUMMYNET_CONFIGURE : case IP_DUMMYNET_DEL : case IP_DUMMYNET_FLUSH : if ( ip_dn_ctl_ptr != NULL ) error = ip_dn_ctl_ptr ( sopt ) ; else error = ENOPROTOOPT ; break ; case IP_RSVP_ON : error = priv_check ( curthread , PRIV_NETINET_MROUTE ) ; if ( error != 0 ) return ( error ) ; error = ip_rsvp_init ( so ) ; break ; case IP_RSVP_OFF : error = priv_check ( curthread , PRIV_NETINET_MROUTE ) ; if ( error != 0 ) return ( error ) ; error = ip_rsvp_done ( ) ; break ; case IP_RSVP_VIF_ON : case IP_RSVP_VIF_OFF : error = priv_check ( curthread , PRIV_NETINET_MROUTE ) ; if ( error != 0 ) return ( error ) ; error = ip_rsvp_vif ? ip_rsvp_vif ( so , sopt ) : EINVAL ; break ; case MRT_INIT : case MRT_DONE : case MRT_ADD_VIF : case MRT_DEL_VIF : case MRT_ADD_MFC : case MRT_DEL_MFC : case MRT_VERSION : case MRT_ASSERT : case MRT_API_SUPPORT : case MRT_API_CONFIG : case MRT_ADD_BW_UPCALL : case MRT_DEL_BW_UPCALL : error = priv_check ( curthread , PRIV_NETINET_MROUTE ) ; if ( error != 0 ) return ( error ) ; error = ip_mrouter_set ? ip_mrouter_set ( so , sopt ) : EOPNOTSUPP ; break ; default : error = ip_ctloutput ( so , sopt ) ; break ; } break ; } return ( error ) ; }
Raw IP socket option processing.
Raw IP socket option processing .
/* generic ipfw v.3 functions */ /* ADD actually returns the body... */ /* generic dummynet v.3 functions */ /* generic ipfw v.3 functions */ /* generic dummynet v.3 functions */