Add a new interface

0

I want to add a new interface by NETLINK. Unfortunately I did not find any example.

My code always ends with an error. I want to add a simple interface "dummy0" (as $ip link add dummy0 type dummy)

void CreateIfc(const char * name)
{ 
  struct {
    struct nlmsghdr  nh;
    struct ifinfomsg ifi;
    rtattr rta0; 
    char ifiname[32];
  } req;

    memset(&req, 0, sizeof(req));
    req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.ifi));
    req.nh.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;

    req.nh.nlmsg_type = RTM_NEWLINK;
    //req.ifi.ifi_index = if_nametoindex("dummy0");
    req.ifi.ifi_change = 0xffffffff;

    req.ifi.ifi_family = AF_PACKET;
    req.ifi.ifi_type = ARPHRD_ETHER;

    strcpy(req.ifiname, "dummy0");
    req.rta0.rta_type = IFLA_IFNAME;
    req.rta0.rta_len = RTA_LENGTH(strlen(req.ifiname) + 1);
    req.nh.nlmsg_len += RTA_ALIGN(req.rta0.rta_len);

    SendNlMsg(&req.nh);
}

I can change the parameters of an already created interface, but I can't add new ones. Does anyone know how to add a new interface by NETLINK?

Thank you...

netlink
asked on Stack Overflow May 20, 2020 by nevs

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0