]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_igmp_join.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pimd / pim_igmp_join.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * PIM for Quagga
4 * Copyright (C) 2008 Everton da Silva Marques
5 */
6
7 #ifndef PIM_IGMP_JOIN_H
8 #define PIM_IGMP_JOIN_H
9
10 /* required headers #include'd by caller */
11
12 #ifndef SOL_IP
13 #define SOL_IP IPPROTO_IP
14 #endif
15
16 #ifndef MCAST_JOIN_GROUP
17 #define MCAST_JOIN_GROUP 42
18 #endif
19
20 #ifndef MCAST_JOIN_SOURCE_GROUP
21 #define MCAST_JOIN_SOURCE_GROUP 46
22 struct group_source_req {
23 uint32_t gsr_interface;
24 struct sockaddr_storage gsr_group;
25 struct sockaddr_storage gsr_source;
26 };
27 #endif
28
29 static inline int pim_igmp_join_source(int fd, ifindex_t ifindex,
30 struct in_addr group_addr,
31 struct in_addr source_addr)
32 {
33 struct group_source_req req;
34 struct sockaddr_in group;
35 struct sockaddr_in source;
36
37 memset(&req, 0, sizeof(req));
38 memset(&group, 0, sizeof(group));
39 group.sin_family = AF_INET;
40 group.sin_addr = group_addr;
41 group.sin_port = htons(0);
42 memcpy(&req.gsr_group, &group, sizeof(struct sockaddr_in));
43
44 memset(&source, 0, sizeof(source));
45 source.sin_family = AF_INET;
46 source.sin_addr = source_addr;
47 source.sin_port = htons(0);
48 memcpy(&req.gsr_source, &source, sizeof(struct sockaddr_in));
49
50 req.gsr_interface = ifindex;
51
52 if (source_addr.s_addr == INADDR_ANY)
53 return setsockopt(fd, SOL_IP, MCAST_JOIN_GROUP, &req,
54 sizeof(req));
55 else
56 return setsockopt(fd, SOL_IP, MCAST_JOIN_SOURCE_GROUP, &req,
57 sizeof(req));
58 }
59
60 #endif /* PIM_IGMP_JOIN_H */