@@ -2291,11 +2291,67 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[],
22912291 return - EINVAL ;
22922292}
22932293
2294+ static size_t tun_get_size (const struct net_device * dev )
2295+ {
2296+ BUILD_BUG_ON (sizeof (u32 ) != sizeof (uid_t ));
2297+ BUILD_BUG_ON (sizeof (u32 ) != sizeof (gid_t ));
2298+
2299+ return nla_total_size (sizeof (uid_t )) + /* OWNER */
2300+ nla_total_size (sizeof (gid_t )) + /* GROUP */
2301+ nla_total_size (sizeof (u8 )) + /* TYPE */
2302+ nla_total_size (sizeof (u8 )) + /* PI */
2303+ nla_total_size (sizeof (u8 )) + /* VNET_HDR */
2304+ nla_total_size (sizeof (u8 )) + /* PERSIST */
2305+ nla_total_size (sizeof (u8 )) + /* MULTI_QUEUE */
2306+ nla_total_size (sizeof (u32 )) + /* NUM_QUEUES */
2307+ nla_total_size (sizeof (u32 )) + /* NUM_DISABLED_QUEUES */
2308+ 0 ;
2309+ }
2310+
2311+ static int tun_fill_info (struct sk_buff * skb , const struct net_device * dev )
2312+ {
2313+ struct tun_struct * tun = netdev_priv (dev );
2314+
2315+ if (nla_put_u8 (skb , IFLA_TUN_TYPE , tun -> flags & TUN_TYPE_MASK ))
2316+ goto nla_put_failure ;
2317+ if (uid_valid (tun -> owner ) &&
2318+ nla_put_u32 (skb , IFLA_TUN_OWNER ,
2319+ from_kuid_munged (current_user_ns (), tun -> owner )))
2320+ goto nla_put_failure ;
2321+ if (gid_valid (tun -> group ) &&
2322+ nla_put_u32 (skb , IFLA_TUN_GROUP ,
2323+ from_kgid_munged (current_user_ns (), tun -> group )))
2324+ goto nla_put_failure ;
2325+ if (nla_put_u8 (skb , IFLA_TUN_PI , !(tun -> flags & IFF_NO_PI )))
2326+ goto nla_put_failure ;
2327+ if (nla_put_u8 (skb , IFLA_TUN_VNET_HDR , !!(tun -> flags & IFF_VNET_HDR )))
2328+ goto nla_put_failure ;
2329+ if (nla_put_u8 (skb , IFLA_TUN_PERSIST , !!(tun -> flags & IFF_PERSIST )))
2330+ goto nla_put_failure ;
2331+ if (nla_put_u8 (skb , IFLA_TUN_MULTI_QUEUE ,
2332+ !!(tun -> flags & IFF_MULTI_QUEUE )))
2333+ goto nla_put_failure ;
2334+ if (tun -> flags & IFF_MULTI_QUEUE ) {
2335+ if (nla_put_u32 (skb , IFLA_TUN_NUM_QUEUES , tun -> numqueues ))
2336+ goto nla_put_failure ;
2337+ if (nla_put_u32 (skb , IFLA_TUN_NUM_DISABLED_QUEUES ,
2338+ tun -> numdisabled ))
2339+ goto nla_put_failure ;
2340+ }
2341+
2342+ return 0 ;
2343+
2344+ nla_put_failure :
2345+ return - EMSGSIZE ;
2346+ }
2347+
22942348static struct rtnl_link_ops tun_link_ops __read_mostly = {
22952349 .kind = DRV_NAME ,
22962350 .priv_size = sizeof (struct tun_struct ),
22972351 .setup = tun_setup ,
22982352 .validate = tun_validate ,
2353+ .get_size = tun_get_size ,
2354+ .fill_info = tun_fill_info ,
22992355};
23002356
23012357static void tun_sock_write_space (struct sock * sk )
0 commit comments