On Wed, Jan 06, 2021 at 10:27:42AM +0100, Claudio Jeker wrote:
> Linux and FreeBSD both support the use of struct ip_mreqn in
> IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. This struct adds one more field
> to pass an interface index to the kernel (instead of using the IP
> address).
>
> struct ip_mreqn {
> struct in_addr imr_multiaddr; /* IP multicast address of group */
> struct in_addr imr_address; /* local IP address of interface */
> int imr_ifindex; /* interface index */
> };
>
> So if imr_ifindex is not 0 then this value is used to define the outgoing
> interface instead of doing a lookup with imr_address.
> This is something I want to use in ospfd(8) to support unnumbered
> interfaces (or actually point-to-point interfaces using the same source
> IP).
>
Here the corresponding ospfd(8) diff to use struct ip_mreqn and the
interface index. With this it should be possible the have the same IP
address set on multiple interfaces.
--
:wq Claudio
Index: interface.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/interface.c,v
retrieving revision 1.84
diff -u -p -r1.84 interface.c
--- interface.c 2 Nov 2020 00:30:56 -0000 1.84
+++ interface.c 6 Jan 2021 09:33:38 -0000
@@ -711,7 +711,7 @@ LIST_HEAD(,if_group_count) ifglist = LIS
int
if_join_group(struct iface *iface, struct in_addr *addr)
{
- struct ip_mreq mreq;
+ struct ip_mreqn mreq;
struct if_group_count *ifg;
switch (iface->type) {
@@ -734,7 +734,7 @@ if_join_group(struct iface *iface, struc
return (0);
mreq.imr_multiaddr.s_addr = addr->s_addr;
- mreq.imr_interface.s_addr = iface->addr.s_addr;
+ mreq.imr_ifindex = iface->ifindex;
if (setsockopt(iface->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(void *)&mreq, sizeof(mreq)) == -1) {
@@ -760,7 +760,7 @@ if_join_group(struct iface *iface, struc
int
if_leave_group(struct iface *iface, struct in_addr *addr)
{
- struct ip_mreq mreq;
+ struct ip_mreqn mreq;
struct if_group_count *ifg;
switch (iface->type) {
@@ -782,7 +782,7 @@ if_leave_group(struct iface *iface, stru
}
mreq.imr_multiaddr.s_addr = addr->s_addr;
- mreq.imr_interface.s_addr = iface->addr.s_addr;
+ mreq.imr_ifindex = iface->ifindex;
if (setsockopt(iface->fd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
(void *)&mreq, sizeof(mreq)) == -1) {