letting kernel configure ipv6 on a tap interface - c

I have a situation where I create a tap interface on linux using C program. I can configure an ipv6 address on this interface as well using the ioctl command SIOCSIFADDR. and it gets set correctly.
But wat i want is to configure only Link-Local address (thats wat i set by above SIOCSIFADDR). and then Let the kernel do the global address allocation through SLAAC procedure. but I only succeed in setting the Link-local address. If I do a service network restart I can see the eth0 interface going UP and i can see the Router Solicitation requests too. but nothing for the interface that i bring up through programming.
Is it possible to create an interface and let kernel manage its ipv6 interfaces itself.

Related

can I tell the network interface type with RTNETLINK?

I'm using RTNETLINK to identify the current gateway, so as to remember the firewall settings based on the Access Point I'm connected to.
WLAN connections give an ESSID that I can use for this purpose, but LAN connections don't, so I fallback to using the MAC address of the gateway as an identifier. But when I use this process on a phone's WWAN data connection, I can't retrieve any MAC address of the gateway.
I found out that in C I can use if_indextoname() on rtmsg->rta_dst->rta_oif to retrieve the outgoing interface name, like in this example, but I guess that there is no guarantee that it will conform to the interface type - it won't translate 1:1 to either WWAN, WLAN or LAN.
Is there a way to find this out in RTNETLINK ? If not, are there other kernel interfaces usable for this purpose ?

How to receive data from tun interface to dpdk binded NIC?

I want to have any Traffic generator(say iperf,D-ITG or even ping) to send data to a tun interface. This tun interface should automatically forward to NIC which is binded to DPDK. I want to run l3fwd example which picks up data from the interface.
I used the option --vdev=net_tun0 in commandline which creates tun interface. I thought tun/tap PMD will automatically poll the packets at tun/tap interface and redirect to/from NIC. But, that's not happening. I am not able to receive any packets.
I require dpdk and traffic generator to run on the same PC. DPDK should pick the traffic at the userspace.
Since the question is not that clear (whether it is DPDK RX-TX or Kernel RX-TX), here are the answers for DPDK application point of view
DPDK TUN PMD allows creating Kernel TUN interface with ip layer
onwards (there is no MAC Layer). just like all PMD devices, you have
to poll with rte_eth_rx_burst and use rte_eth_tx_burst inside
DPDK Application.
Similarly, if you plan to use TAP PMD, dpdk will create Kernel TAP
the interface which has to be polled with rte_eth_rx_burst and
rte_eth_tx_burst inside DPDK application.
Once you use vdev=net_tap0 this creates Kernel tap interface dtap0. So to grab packets received to Kernel interface you have call rte_eth_rx_burst to send a specific packet to Kernel TAP interface you need to use rte_eth_tx_burst.
as per your requirement which is to direct any traffic generator to kernel to TAP interface, then send to physical NIC bound with DPDK, this what you have to do
make use a simple application like examples/skeleton or testpmd or examples/l2fwd with no mac update`
ensure you pass the vdev=net_tap0,iface=<your desired name for interface> to the DPDK application.
Using ip or ifconfig bring up the interface with ip address and the state as up (Promisc mode is optional).
ensure your destination address route is through tap interface by cross-checking route -n.
now kick start your traffic generator with dest-ip and interface as required.
Note: In my deployment case, I ended up setting static ARP too.
This will send the packet to kernel TAP interface, which is then intercepted by DPDK application via rx_burst calls. Using port to port forward behaviour this is then forwarded to DPDK Physical NIC. In reverse direction, the packet received from physical nic is bought into the application by rx_burst and then tx_burst to TAP PMD. this will then inject to the kernel TAP interface.

what is interface in socket programming?

"INADDR_ANY binds the socket to all available interfaces."
This is the statement i Encountered.I found it here
What is interface here? Is it a port number or something else?
And another question is
Is interface and channel or one and same?
Usually your host (your computer) has more than one interfaces. For example, (older) computer without network would have only IPv4 loopback interface.
If you add and configure IPv4 network to that PC, you'll get another interface: eth0, or net0 or something similar.
When you install VPN, it will create you yet another interface, as instead of sending packets into unsecured network, you send it into logical VPN interface, and that one forwards data to eth0 after some processing.
Every time, when you add a hardware link (with driver) to a network, or create logical network, it creates you a new interface. For example, if you use VMVare, and create virtual machine, the system would provider you some set of interfaces needed to route data between your host, network, and virtual machine.
When routing IPv4, every interface is assigned IPv4 address. Even loopback (127.0.0.1). The address can be static, or obtained from server when your system boots.
So you can listen only on one interface. For example, if you bind to loopback, you will not be able to access any network, and network hosts will not be able to access your socket (assuming routing is not broken). But you connect multiple processes on your host to each other.
If you bind to particular network interface, it means you want to work with systems, that are connected to that network (directly or indirectly).
If you bind to any, for server sockets it means you let system to accept connections from anywhere, considering that anywhere can ping you.
As per my understanding the socket interface is something like this
Gives a file system like abstraction to the capabilities of the
network.
Each transport protocol offers a set of services. The socket API
provides the abstraction to access these services
The API defines function calls to create, close, read and write
to/from a socket.
Also something like this also
A network interface is the point of interconnection between a computer and a private or public network. A network interface is generally a network interface card (NIC), but does not have to have a physical form. Instead, the network interface can be implemented in software.
For example, the loopback interface (127.0.0.1 for IPv4 and ::1 for IPv6) is not a physical device but a piece of software simulating a network interface. The loopback interface is commonly used in test environments
Examples for interfaces:
your LAN card where you can plug a network cable,
a wifi adapter,
a (software-only) thing which provides an imaginary network between your main system and a virtual machine
the (software-only) loopback adapter which sends everything you send to it "back" to your own computer
etc. If you´re writing a socket server, you can choose
where the client connections may come from.
Only from a virtual machine, but no real computer outside?
Only wifi, but no cable-bound LAN? Or just all together?

is there a way to know whether tun/tap interface is opened?

I am making an application using tun interface tun0. I have been successfully able to send and receive packets through the interface. Is there any way to know when the tun interface is opened as in ifconfig tun0 up?
I want do some part of my underlying device initialization only when the interface is active.
(added later)
I am following the examples from http://backreference.org/2010/03/26/tuntap-interface-tutorial/

What should the destination mac address be set to when sending packet outside of your local network?

If I use arp and arping on machines in my local network I get the mac addresses from them. In the same way I can construct and send a ARP request and collect the response to these machines. This is used since I build raw packets completely from scratchy (to allow spoofing of every possible field, including mac addresses if needed). But, when I try arping or arp on external ip's and hosts such as google.com it doesn't get any reply. What should the destination mac address be set to when sending packets to targets outside my local network? I guess the router since that's what passes it on... am I correct? Is there a quick way in ANSI C to collect the mac address of the router in use by the computer? Or at least the IP so I can send a ARP request to it.
Thanx in advance
MAC operations are limited to machines directly connected within your subnet. So you should use the router's MAC address for packets intended for hosts outside your subnet.
There are numerous ways to obtain the router's IP address.
You can parse the configuration files on your local host if the interface is statically configured.
You can see if your compute platform has an API that lets you access the interface configuration information directly. This would work in both static and dhcp cases.
You can write socket code to send an ICMP message to an outside address then parse the incoming responses. They will be from the router. The stack will, in this case, find the router for you.
It should be set to the gateway (assuming ethernet on that link...).

Resources