/** * fip_socket_sanmac - add SAN MAC to the unicast list for input socket * @s: ETH_P_FIP packet socket to setsockopt on * @ifindex: network interface index to send on * @add: 1 to add 0 to del */ static int fip_socket_sanmac(int s, int ifindex, unsigned char *mac, int add) { unsigned char smac[ETHER_ADDR_LEN]; if (fip_get_sanmac(ifindex, smac)) { FIP_LOG_DBG("%s: no sanmac, ifindex %d\n", __func__, ifindex); memcpy(smac, mac, ETHER_ADDR_LEN); } return fip_socket_add_addr(s, ifindex, add, smac, false); }
/** * fip_socket_sanmac - add SAN MAC to the unicast list for input socket * @s: ETH_P_FIP packet socket to setsockopt on * @ifindex: network interface index to send on * @add: 1 to add 0 to del */ static void fip_socket_sanmac(int s, int ifindex, int add) { struct packet_mreq mr; unsigned char smac[ETHER_ADDR_LEN]; if (fip_get_sanmac(ifindex, smac)) return; memset(&mr, 0, sizeof(mr)); mr.mr_ifindex = ifindex; mr.mr_type = PACKET_MR_UNICAST; mr.mr_alen = ETHER_ADDR_LEN; memcpy(mr.mr_address, smac, ETHER_ADDR_LEN); if (setsockopt(s, SOL_PACKET, (add) ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP, &mr, sizeof(mr)) < 0) FIP_LOG_DBG("PACKET_%s_MEMBERSHIP:failed\n", (add) ? "ADD" : "DROP"); }
/** * fip_socket_add_addr - add a MAC address to the input socket * @s: ETH_P_FIP packet socket to setsockopt on * @ifindex: network interface index to send on * @add: true to add false to del * @mac: MAC address to add or delete * @multi: false if unicast, true if multicast address */ static int fip_socket_add_addr(int s, int ifindex, bool add, const __u8 *mac, bool multi) { struct packet_mreq mr; int rc = 0; memset(&mr, 0, sizeof(mr)); mr.mr_ifindex = ifindex; mr.mr_type = multi ? PACKET_MR_MULTICAST : PACKET_MR_UNICAST; mr.mr_alen = ETHER_ADDR_LEN; memcpy(mr.mr_address, mac, ETHER_ADDR_LEN); if (setsockopt(s, SOL_PACKET, add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP, &mr, sizeof(mr)) < 0) { FIP_LOG_DBG("PACKET_%s_MEMBERSHIP:failed\n", add ? "ADD" : "DROP"); rc = -errno; } return rc; }