title: Obtaining real device of VLAN-interface through the netlink
body: <p>I need to obtain the <a href="https://elixir.bootlin.com/linux/v4.4.172/source/net/8021q/vlan.h#L29" rel="nofollow noreferrer"><code>real_dev</code></a> (f.e. ID) of the given VLAN-inteface.</p>
  
  <p>I wrote some test snippet using <a href="https://www.infradead.org/~tgr/libnl/doc/api/" rel="nofollow noreferrer"><em>libnl</em></a>:</p>
  
  <pre><code>int main(void) {
       struct nl_sock *sock;
       struct nl_cache *cache;
       char iface[] = "eno1.10";
       //char iface[] = "eno1";
  
       if (!(sock = nl_socket_alloc())) {
            perror("nl_socket_alloc");
            return -1; 
       }
  
       if (nl_connect(sock, NETLINK_ROUTE) &lt; 0) {
            perror("nl_connect");
            nl_socket_free( sock );
            return -1; 
       }
  
       if (rtnl_link_alloc_cache(sock, AF_UNSPEC, &amp;cache) &lt; 0) {
            perror("rtnl_link_alloc_cache");
            nl_socket_free( sock );
            nl_close( sock );
            return -1; 
       }
       {   
            int ifindex; 
            struct rtnl_link *link = NULL;
  
            if (!(ifindex = rtnl_link_name2i(cache, iface))) {
                 perror("rtnl_link_name2i");
                 return -1; 
            }
            printf("ind: %d\n", ifindex);
  
            if (!(link = rtnl_link_get(cache, ifindex))) {
                 perror("rtnl_link_get");
                 return -1; 
            }
  
            if (rtnl_link_is_vlan(link)) {
                 puts("It's VLAN link");
  
                 /* alas it's not about the 'real' device */
                 printf("master: %d\n", rtnl_link_get_master(link));
            } else
                 puts("It's 'real' link");
       }   
  
       return 0;
  }
  </code></pre>
  
  <p>So I have some <em>interface ID</em> and I can check if it's a VLAN-interface, but I have no idea <strong><em>how to obtain the interface the vlan is attached to</em></strong>.
  It seems that <em>libnl</em>'s API does not provide such possibility.</p>
  
  <p>Is there a way to obtain the VLAN's "parent" interface ID through the <em>libnl</em> or the <em>native netlink API</em>?</p>