Topics

sw_if_index in vent_buffer giving wrong IP address with ip_interface_address_get_address


RaviKiran Veldanda
 
Edited

Hi Team,
I am writing a plugin and my plugin is attached to device_input, so that I can receive all the traffic.
In my plugin, I am checking the headers and deciding to forward to my application or to the Native VPP. This is working fine, However ICMP case I have one requirement to check is it destined to Interface I attached my plugin or some other IP, So to check that I am using following APIs, 
I am receiving packets and doing following things to get the IP address,
sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
ip4_main_t *im = &ip4_main;
 ip_lookup_main_t *lm = &im->lookup_main;
 ip_interface_address_t *if_add = pool_elt_at_index (lm->if_address_pool, if_index);
 ip4_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
I am getting IP Address but the IP Address I am getting is something different,
For Example:
In VPPCTL If I create the interfaces in the following order:
 set interface ip add HundredGigabitEthernet12/0/0 192.168.198.2/24
 set interface state HundredGigabitEthernet12/0/0 up
 set interface ip addr HundredGigabitEthernet12/0/0 2001:5b0:ffff:7cf0::98fc/64
 create interface 
memif id 0 socket-id 0 master
 set interface state memif0/0 up
 set interface ip add memif0/0 
192.168.1.3/24
 set interface ip addr memif0/0 2001:5b0:ffff:7cf1::98fc/64
  I am getting IP Address as 192.168.1.3.
If I am creating interfaces in the following order:
 create interface memif id 0 socket-id 0 master
 set interface state memif0/0 up
 set interface ip add memif0/0 
192.168.1.3/24
 set interface ip addr memif0/0 2001:5b0:ffff:7cf1::98fc/64
  
  set interface ip add HundredGigabitEthernet12/0/0 192.168.198.2/24
 set interface state HundredGigabitEthernet12/0/0 up
 set interface ip addr HundredGigabitEthernet12/0/0 2001:5b0:ffff:7cf0::98fc/64
 
I am getting IP Address as 192.168.198.2.

But in both cases the sw_if_index is same and my plugin attached to the HundredGigabitEthernet12/0/0 only. I am expecting IP address of this but its getting the order I created.
So My questions are
1> How to get IP address of a interface from sw_if_index0?
2> Can you please let me know if you find any issue in my code to get the IP Address?
3> Is there any better method to get IP address from the buffer using any other parameter? I needed IP address of interface the packet received.
 
Regards,
Ravi.


Dave Barach
 

If the packet was received on HundredGigabitEthernet12/0/0, you should get 192.168.198.2. If it was received on memif0/0 you should get 192.168.1.3. "trace add dpdk-input" [or send pkts, then "show trace". If that produces nothing, s/dpdk-input/memif-input/ or whatever the memif input node is called.

Use "show int addr" / "show int" to determine the sw_if_index to name mapping, and to display the interface ip addresses.


From: discuss@... <discuss@...> on behalf of ravi.jupvpp@... <ravi.jupvpp@...>
Sent: Thursday, June 18, 2020 3:54 PM
To: discuss@... <discuss@...>
Subject: [discuss] sw_if_index in vent_buffer giving wrong IP address with ip_interface_address_get_address
 

[Edited Message Follows]

Hi Team,
I am writing a plugin and my plugin is attached to device_input, so that I can receive all the traffic.
In my plugin, I am checking the headers and deciding to forward to my application or to the Native VPP. This is working fine, However ICMP case I have one requirement to check is it destined to Interface I attached my plugin or some other IP, So to check that I am using following APIs, 
I am receiving packets and doing following things to get the IP address,
sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
ip4_main_t *im = &ip4_main;
 ip_lookup_main_t *lm = &im->lookup_main;
 ip_interface_address_t *if_add = pool_elt_at_index (lm->if_address_pool, if_index);
 ip4_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
I am getting IP Address but the IP Address I am getting is something different,
For Example:
In VPPCTL If I create the interfaces in the following order:
 set interface ip add HundredGigabitEthernet12/0/0 192.168.198.2/24
 set interface state HundredGigabitEthernet12/0/0 up
 set interface ip addr HundredGigabitEthernet12/0/0 2001:5b0:ffff:7cf0::98fc/64
 create interface 
memif id 0 socket-id 0 master
 set interface state memif0/0 up
 set interface ip add memif0/0 
192.168.1.3/24
 set interface ip addr memif0/0 2001:5b0:ffff:7cf1::98fc/64
  I am getting IP Address as 192.168.1.3.
If I am creating interfaces in the following order:
 create interface memif id 0 socket-id 0 master
 set interface state memif0/0 up
 set interface ip add memif0/0 
192.168.1.3/24
 set interface ip addr memif0/0 2001:5b0:ffff:7cf1::98fc/64
  
  set interface ip add HundredGigabitEthernet12/0/0 192.168.198.2/24
 set interface state HundredGigabitEthernet12/0/0 up
 set interface ip addr HundredGigabitEthernet12/0/0 2001:5b0:ffff:7cf0::98fc/64
 
I am getting IP Address as 192.168.198.2.

But in both cases the sw_if_index is same and my plugin attached to the HundredGigabitEthernet12/0/0 only. I am expecting IP address of this but its getting the order I created.
So My questions are
1> How to get IP address of a interface from sw_if_index0?
2> Can you please let me know if you find any issue in my code to get the IP Address?
3> Is there any better method to get IP address from the buffer using any other parameter? I needed IP address of interface the packet received.
 
Regards,
Ravi.