Everton Marques | 40765fe | 2009-09-30 17:10:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | PIM for Quagga |
| 3 | Copyright (C) 2008 Everton da Silva Marques |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, but |
| 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; see the file COPYING; if not, write to the |
| 17 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 18 | MA 02110-1301 USA |
| 19 | |
| 20 | $QuaggaId: $Format:%an, %ai, %h$ $ |
| 21 | */ |
| 22 | |
David Lamparter | 821df2c | 2015-09-15 01:53:09 -0700 | [diff] [blame] | 23 | #include <zebra.h> |
| 24 | |
User | d0d7980 | 2010-08-05 13:26:25 -0700 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | #include <sys/socket.h> |
Everton Marques | 40765fe | 2009-09-30 17:10:11 -0300 | [diff] [blame] | 27 | #include <string.h> |
| 28 | |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 29 | #include "zebra.h" |
Everton Marques | 40765fe | 2009-09-30 17:10:11 -0300 | [diff] [blame] | 30 | #include "pim_igmp_join.h" |
| 31 | |
User | d0d7980 | 2010-08-05 13:26:25 -0700 | [diff] [blame] | 32 | #ifndef SOL_IP |
| 33 | #define SOL_IP IPPROTO_IP |
| 34 | #endif |
| 35 | |
Everton Marques | 40765fe | 2009-09-30 17:10:11 -0300 | [diff] [blame] | 36 | #ifndef MCAST_JOIN_SOURCE_GROUP |
| 37 | #define MCAST_JOIN_SOURCE_GROUP 46 |
| 38 | struct group_source_req |
| 39 | { |
| 40 | uint32_t gsr_interface; |
| 41 | struct sockaddr_storage gsr_group; |
| 42 | struct sockaddr_storage gsr_source; |
| 43 | }; |
| 44 | #endif |
| 45 | |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 46 | int pim_igmp_join_source(int fd, ifindex_t ifindex, |
Everton Marques | 40765fe | 2009-09-30 17:10:11 -0300 | [diff] [blame] | 47 | struct in_addr group_addr, |
| 48 | struct in_addr source_addr) |
| 49 | { |
| 50 | struct group_source_req req; |
Donald Sharp | 26a18eb | 2015-09-29 09:25:10 -0400 | [diff] [blame] | 51 | struct sockaddr_in group; |
| 52 | struct sockaddr_in source; |
Everton Marques | 40765fe | 2009-09-30 17:10:11 -0300 | [diff] [blame] | 53 | |
Donald Sharp | 26a18eb | 2015-09-29 09:25:10 -0400 | [diff] [blame] | 54 | memset(&group, 0, sizeof(group)); |
| 55 | group.sin_family = AF_INET; |
| 56 | group.sin_addr = group_addr; |
| 57 | group.sin_port = htons(0); |
| 58 | memcpy(&req.gsr_group, &group, sizeof(struct sockaddr_in)); |
Everton Marques | 40765fe | 2009-09-30 17:10:11 -0300 | [diff] [blame] | 59 | |
Donald Sharp | 26a18eb | 2015-09-29 09:25:10 -0400 | [diff] [blame] | 60 | memset(&source, 0, sizeof(source)); |
| 61 | source.sin_family = AF_INET; |
| 62 | source.sin_addr = source_addr; |
| 63 | source.sin_port = htons(0); |
| 64 | memcpy(&req.gsr_source, &source, sizeof(struct sockaddr_in)); |
Everton Marques | 40765fe | 2009-09-30 17:10:11 -0300 | [diff] [blame] | 65 | |
| 66 | req.gsr_interface = ifindex; |
| 67 | |
| 68 | return setsockopt(fd, SOL_IP, MCAST_JOIN_SOURCE_GROUP, |
| 69 | &req, sizeof(req)); |
| 70 | |
| 71 | return 0; |
| 72 | } |