History

sit: advertise tunnel param via rtnl

It is usefull for daemons that monitor link event to have the full parameters of these interfaces when a rtnl message is sent. It allows also to dump them via rtnetlink. It is based on what is done for GRE tunnels.

Nicolas Dichtel committed 14 years ago

Commit ba3e3f51 parent 09746581 file · +56 −1Browse files

Unified · Split

net/ipv6/sit.c+56−1
@@ -68,6 +68,7 @@ · 67 unmodified lines
6868 static int ipip6_tunnel_init(struct net_device *dev);
6969 static void ipip6_tunnel_setup(struct net_device *dev);
7070 static void ipip6_dev_free(struct net_device *dev);
71+static struct rtnl_link_ops sit_link_ops __read_mostly;
7172
7273 static int sit_net_id __read_mostly;
7374 struct sit_net {
@@ -282,6 +283,7 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, · 208 unmodified lines
282283 goto failed_free;
283284
284285 strcpy(nt->parms.name, dev->name);
286+ dev->rtnl_link_ops = &sit_link_ops;
285287
286288 dev_hold(dev);
287289
@@ -1216,6 +1218,47 @@ static int __net_init ipip6_fb_tunnel_init(struct net_device *dev) · 928 unmodified lines
12161218 return 0;
12171219 }
12181220
1221+static size_t sit_get_size(const struct net_device *dev)
1222+{
1223+ return
1224+ /* IFLA_IPTUN_LINK */
1225+ nla_total_size(4) +
1226+ /* IFLA_IPTUN_LOCAL */
1227+ nla_total_size(4) +
1228+ /* IFLA_IPTUN_REMOTE */
1229+ nla_total_size(4) +
1230+ /* IFLA_IPTUN_TTL */
1231+ nla_total_size(1) +
1232+ /* IFLA_IPTUN_TOS */
1233+ nla_total_size(1) +
1234+ 0;
1235+}
1236+
1237+static int sit_fill_info(struct sk_buff *skb, const struct net_device *dev)
1238+{
1239+ struct ip_tunnel *tunnel = netdev_priv(dev);
1240+ struct ip_tunnel_parm *parm = &tunnel->parms;
1241+
1242+ if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
1243+ nla_put_be32(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) ||
1244+ nla_put_be32(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) ||
1245+ nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) ||
1246+ nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos))
1247+ goto nla_put_failure;
1248+ return 0;
1249+
1250+nla_put_failure:
1251+ return -EMSGSIZE;
1252+}
1253+
1254+static struct rtnl_link_ops sit_link_ops __read_mostly = {
1255+ .kind = "sit",
1256+ .maxtype = IFLA_IPTUN_MAX,
1257+ .priv_size = sizeof(struct ip_tunnel),
1258+ .get_size = sit_get_size,
1259+ .fill_info = sit_fill_info,
1260+};
1261+
12191262 static struct xfrm_tunnel sit_handler __read_mostly = {
12201263 .handler = ipip6_rcv,
12211264 .err_handler = ipip6_err,
@@ -1302,6 +1345,7 @@ static struct pernet_operations sit_net_ops = { · 80 unmodified lines
13021345
13031346 static void __exit sit_cleanup(void)
13041347 {
1348+ rtnl_link_unregister(&sit_link_ops);
13051349 xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
13061350
13071351 unregister_pernet_device(&sit_net_ops);
@@ -1319,10 +1363,21 @@ static int __init sit_init(void) · 11 unmodified lines
13191363 return err;
13201364 err = xfrm4_tunnel_register(&sit_handler, AF_INET6);
13211365 if (err < 0) {
1322− unregister_pernet_device(&sit_net_ops);
13231366 pr_info("%s: can't add protocol\n", __func__);
1367+ goto xfrm_tunnel_failed;
13241368 }
1369+ err = rtnl_link_register(&sit_link_ops);
1370+ if (err < 0)
1371+ goto rtnl_link_failed;
1372+
1373+out:
13251374 return err;
1375+
1376+rtnl_link_failed:
1377+ xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
1378+xfrm_tunnel_failed:
1379+ unregister_pernet_device(&sit_net_ops);
1380+ goto out;
13261381 }
13271382
13281383 module_init(sit_init);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t