Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Set Interface Index Using the IP_PKTINFO #2980

Open
maxsharabayko opened this issue Jul 11, 2024 · 0 comments · May be fixed by #2982
Open

[BUG] Set Interface Index Using the IP_PKTINFO #2980

maxsharabayko opened this issue Jul 11, 2024 · 0 comments · May be fixed by #2982
Labels
[core] Area: Changes in SRT library core Type: Bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@maxsharabayko
Copy link
Collaborator

Short Description

A listener is bound to SOCKADDR_ANY receiving packets from two or more NICs.
pktinfo.ipi_ifindex is set to 0 for outcoming packets meaning the system can use its routing tables for selecting an interface.
Maybe in case PKTINFO is enable the desire is to always reply over the same interface, therefore, the ifindex has to be set accordingly.

SRT v1.5.2 and above (since the introduction of the SRT_ENABLE_PKTINFO).

Problem Description

Let's assume some PC has a single network interface (single IPv4 address) and is calling another PC (with two NICS) using active-backup redundancy.
Having the --enable-pktinfo option enabled does not guarantee the response would be over a correct interface. The response would go over whatever local address for the source IP with a 50/50 chance of being correct and the connection would fail.
The --enable-pkinfo compilation does not enforce that response packets should be sent out on the same interface from which packets were received. While the source IP to be used is grabbed using the pktinfo option, the received network interface is left to 0 meaning the system will use whatever it wants based on the current routing table.

Here the code in channel.h that uses IP_PKTINFO

if (adr.family() == AF_INET)
{
	mh.msg_control = (void *) buf;
	mh.msg_controllen = CMSG_SPACE(sizeof(struct in_pktinfo));

	cmsghdr* cmsg_send = CMSG_FIRSTHDR(&mh);
	cmsg_send->cmsg_level = IPPROTO_IP;
	cmsg_send->cmsg_type = IP_PKTINFO;
	cmsg_send->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
	
	in_pktinfo pktinfo;
	pktinfo.ipi_ifindex = 0;
	pktinfo.ipi_spec_dst = adr.sin.sin_addr;
	memcpy(CMSG_DATA(cmsg_send), &pktinfo, sizeof(in_pktinfo));

	return true;
}

Notice the ipi_ifindex being set to zero

This paragraph from https://man7.org/linux/man-pages/man7/ip.7.html explains the option:

ipi_ifindex is the unique index of the interface the
              packet was received on.  ipi_spec_dst is the local address
              of the packet and ipi_addr is the destination address in
              the packet header.  If IP_PKTINFO is passed to sendmsg(2)
              and ipi_spec_dst is not zero, then it is used as the local
              source address for the routing table lookup and for
              setting up IP source route options.  When ipi_ifindex is
              not zero, the primary local address of the interface
              specified by the index overwrites ipi_spec_dst for the
              routing table lookup.

Probably virtually in all cases we would want packets related to a SRT connection to use the same interface has what was received....

In any case the idea would either to

  1. always force the output interface when --enable-pktinfo
  2. provide an other option to let the application force the setting of the output interface to match the input interface or not.

Option a) seems simpler but maybe we need input from other users?

@maxsharabayko maxsharabayko added Type: Bug Indicates an unexpected problem or unintended behavior [core] Area: Changes in SRT library core labels Jul 11, 2024
@maxsharabayko maxsharabayko added this to the v1.5.4 milestone Jul 11, 2024
@maxsharabayko maxsharabayko modified the milestones: v1.5.4, v1.6.0 Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Type: Bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant