rtnetlink.c (d37512a277dfb2cef8a578e25a3246f61399a55a) | rtnetlink.c (317f4810e45eebe65d4f8897670df8b779de1467) |
---|---|
1/* 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of communication with the user level. 5 * 6 * Routing netlink socket interface: protocol independent part. 7 * 8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> --- 1234 unchanged lines hidden (view full) --- 1243 [IFLA_AF_SPEC] = { .type = NLA_NESTED }, 1244 [IFLA_EXT_MASK] = { .type = NLA_U32 }, 1245 [IFLA_PROMISCUITY] = { .type = NLA_U32 }, 1246 [IFLA_NUM_TX_QUEUES] = { .type = NLA_U32 }, 1247 [IFLA_NUM_RX_QUEUES] = { .type = NLA_U32 }, 1248 [IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN }, 1249 [IFLA_CARRIER_CHANGES] = { .type = NLA_U32 }, /* ignored */ 1250 [IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN }, | 1/* 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of communication with the user level. 5 * 6 * Routing netlink socket interface: protocol independent part. 7 * 8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> --- 1234 unchanged lines hidden (view full) --- 1243 [IFLA_AF_SPEC] = { .type = NLA_NESTED }, 1244 [IFLA_EXT_MASK] = { .type = NLA_U32 }, 1245 [IFLA_PROMISCUITY] = { .type = NLA_U32 }, 1246 [IFLA_NUM_TX_QUEUES] = { .type = NLA_U32 }, 1247 [IFLA_NUM_RX_QUEUES] = { .type = NLA_U32 }, 1248 [IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN }, 1249 [IFLA_CARRIER_CHANGES] = { .type = NLA_U32 }, /* ignored */ 1250 [IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN }, |
1251 [IFLA_LINK_NETNSID] = { .type = NLA_S32 }, |
|
1251}; 1252 1253static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { 1254 [IFLA_INFO_KIND] = { .type = NLA_STRING }, 1255 [IFLA_INFO_DATA] = { .type = NLA_NESTED }, 1256 [IFLA_INFO_SLAVE_KIND] = { .type = NLA_STRING }, 1257 [IFLA_INFO_SLAVE_DATA] = { .type = NLA_NESTED }, 1258}; --- 757 unchanged lines hidden (view full) --- 2016 ops = NULL; 2017 } 2018 2019 if (1) { 2020 struct nlattr *attr[ops ? ops->maxtype + 1 : 0]; 2021 struct nlattr *slave_attr[m_ops ? m_ops->slave_maxtype + 1 : 0]; 2022 struct nlattr **data = NULL; 2023 struct nlattr **slave_data = NULL; | 1252}; 1253 1254static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { 1255 [IFLA_INFO_KIND] = { .type = NLA_STRING }, 1256 [IFLA_INFO_DATA] = { .type = NLA_NESTED }, 1257 [IFLA_INFO_SLAVE_KIND] = { .type = NLA_STRING }, 1258 [IFLA_INFO_SLAVE_DATA] = { .type = NLA_NESTED }, 1259}; --- 757 unchanged lines hidden (view full) --- 2017 ops = NULL; 2018 } 2019 2020 if (1) { 2021 struct nlattr *attr[ops ? ops->maxtype + 1 : 0]; 2022 struct nlattr *slave_attr[m_ops ? m_ops->slave_maxtype + 1 : 0]; 2023 struct nlattr **data = NULL; 2024 struct nlattr **slave_data = NULL; |
2024 struct net *dest_net; | 2025 struct net *dest_net, *link_net = NULL; |
2025 2026 if (ops) { 2027 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) { 2028 err = nla_parse_nested(attr, ops->maxtype, 2029 linkinfo[IFLA_INFO_DATA], 2030 ops->policy); 2031 if (err < 0) 2032 return err; --- 89 unchanged lines hidden (view full) --- 2122 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind); 2123 name_assign_type = NET_NAME_ENUM; 2124 } 2125 2126 dest_net = rtnl_link_get_net(net, tb); 2127 if (IS_ERR(dest_net)) 2128 return PTR_ERR(dest_net); 2129 | 2026 2027 if (ops) { 2028 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) { 2029 err = nla_parse_nested(attr, ops->maxtype, 2030 linkinfo[IFLA_INFO_DATA], 2031 ops->policy); 2032 if (err < 0) 2033 return err; --- 89 unchanged lines hidden (view full) --- 2123 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind); 2124 name_assign_type = NET_NAME_ENUM; 2125 } 2126 2127 dest_net = rtnl_link_get_net(net, tb); 2128 if (IS_ERR(dest_net)) 2129 return PTR_ERR(dest_net); 2130 |
2130 dev = rtnl_create_link(dest_net, ifname, name_assign_type, ops, tb); | 2131 if (tb[IFLA_LINK_NETNSID]) { 2132 int id = nla_get_s32(tb[IFLA_LINK_NETNSID]); 2133 2134 link_net = get_net_ns_by_id(dest_net, id); 2135 if (!link_net) { 2136 err = -EINVAL; 2137 goto out; 2138 } 2139 } 2140 2141 dev = rtnl_create_link(link_net ? : dest_net, ifname, 2142 name_assign_type, ops, tb); |
2131 if (IS_ERR(dev)) { 2132 err = PTR_ERR(dev); 2133 goto out; 2134 } 2135 2136 dev->ifindex = ifm->ifi_index; 2137 2138 if (ops->newlink) { --- 11 unchanged lines hidden (view full) --- 2150 } else { 2151 err = register_netdevice(dev); 2152 if (err < 0) { 2153 free_netdev(dev); 2154 goto out; 2155 } 2156 } 2157 err = rtnl_configure_link(dev, ifm); | 2143 if (IS_ERR(dev)) { 2144 err = PTR_ERR(dev); 2145 goto out; 2146 } 2147 2148 dev->ifindex = ifm->ifi_index; 2149 2150 if (ops->newlink) { --- 11 unchanged lines hidden (view full) --- 2162 } else { 2163 err = register_netdevice(dev); 2164 if (err < 0) { 2165 free_netdev(dev); 2166 goto out; 2167 } 2168 } 2169 err = rtnl_configure_link(dev, ifm); |
2158 if (err < 0) | 2170 if (err < 0) { |
2159 unregister_netdevice(dev); | 2171 unregister_netdevice(dev); |
2172 goto out; 2173 } 2174 2175 if (link_net) 2176 err = dev_change_net_namespace(dev, dest_net, ifname); |
|
2160out: | 2177out: |
2178 if (link_net) 2179 put_net(link_net); |
|
2161 put_net(dest_net); 2162 return err; 2163 } 2164} 2165 2166static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh) 2167{ 2168 struct net *net = sock_net(skb->sk); --- 1056 unchanged lines hidden --- | 2180 put_net(dest_net); 2181 return err; 2182 } 2183} 2184 2185static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh) 2186{ 2187 struct net *net = sock_net(skb->sk); --- 1056 unchanged lines hidden --- |