MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ip6_setmoptions

Function ip6_setmoptions

freebsd/netinet6/in6_mcast.c:2625–2722  ·  view source on GitHub ↗

* Set the IP multicast options in response to user setsockopt(). * * Many of the socket options handled in this function duplicate the * functionality of socket options in the regular unicast API. However, * it is not possible to merge the duplicate code, because the idempotence * of the IPv6 multicast part of the BSD Sockets API must be preserved; * the effects of these options must be trea

Source from the content-addressed store, hash-verified

2623 * SMPng: XXX: Unlocked read of inp_socket believed OK.
2624 */
2625int
2626ip6_setmoptions(struct inpcb *inp, struct sockopt *sopt)
2627{
2628 struct ip6_moptions *im6o;
2629 int error;
2630
2631 error = 0;
2632
2633 /*
2634 * If socket is neither of type SOCK_RAW or SOCK_DGRAM,
2635 * or is a divert socket, reject it.
2636 */
2637 if (inp->inp_socket->so_proto->pr_protocol == IPPROTO_DIVERT ||
2638 (inp->inp_socket->so_proto->pr_type != SOCK_RAW &&
2639 inp->inp_socket->so_proto->pr_type != SOCK_DGRAM))
2640 return (EOPNOTSUPP);
2641
2642 switch (sopt->sopt_name) {
2643 case IPV6_MULTICAST_IF:
2644 error = in6p_set_multicast_if(inp, sopt);
2645 break;
2646
2647 case IPV6_MULTICAST_HOPS: {
2648 int hlim;
2649
2650 if (sopt->sopt_valsize != sizeof(int)) {
2651 error = EINVAL;
2652 break;
2653 }
2654 error = sooptcopyin(sopt, &hlim, sizeof(hlim), sizeof(int));
2655 if (error)
2656 break;
2657 if (hlim < -1 || hlim > 255) {
2658 error = EINVAL;
2659 break;
2660 } else if (hlim == -1) {
2661 hlim = V_ip6_defmcasthlim;
2662 }
2663 im6o = in6p_findmoptions(inp);
2664 im6o->im6o_multicast_hlim = hlim;
2665 INP_WUNLOCK(inp);
2666 break;
2667 }
2668
2669 case IPV6_MULTICAST_LOOP: {
2670 u_int loop;
2671
2672 /*
2673 * Set the loopback flag for outgoing multicast packets.
2674 * Must be zero or one.
2675 */
2676 if (sopt->sopt_valsize != sizeof(u_int)) {
2677 error = EINVAL;
2678 break;
2679 }
2680 error = sooptcopyin(sopt, &loop, sizeof(u_int), sizeof(u_int));
2681 if (error)
2682 break;

Callers 1

ip6_ctloutputFunction · 0.85

Calls 7

in6p_set_multicast_ifFunction · 0.85
sooptcopyinFunction · 0.85
in6p_findmoptionsFunction · 0.85
in6p_join_groupFunction · 0.85
in6p_leave_groupFunction · 0.85
in6p_set_source_filtersFunction · 0.85

Tested by

no test coverage detected