I have written some VPN software which now needs to be able to be able to tag de-tunnelled traffic with MPLS tags.
I've looked at the source of Mausezahn (which can send MPLS packets) and it seems to construct the whole ethernet frame, using various helper functions, and then gives that ethernet frame to the kernel with libnet_write
.
staging/send_eth.c:
...
tmpls = libnet_build_mpls(tx.mpls_label,
tx.mpls_exp,
tx.mpls_bos,
tx.mpls_ttl,
NULL,
0,
l,
0);
...
t = libnet_build_ethernet (tx.eth_dst,
tx.eth_src,
tx.eth_type,
tx.eth_payload,
tx.eth_payload_s,
L,
t);
if (t == -1)
{
fprintf(stderr, " mz/create_eth_frame: Can't build Ethernet header: %s\n",
libnet_geterror(l));
exit(EXIT_FAILURE);
}
if (verbose) (void) print_frame_details();
libnet_write(L);
...
My code currently uses an IP-level tunnel interface (e.g. tun0) to deliver packets into the kernel.
If I wish to use MPLS will I need to start using a tap interface instead?
Or is there another way, such as ioctls on tun0's fd?
Or do I need to use libnet_write
?