Previously l2tp module did not provide any means for the user space to get notified when tunnels/sessions are added/modified/deleted. This change contains the following - create a multicast group for the listeners to register. - notify the registered listeners when the tunnels/sessions are created/modified/deleted.
Unified · Split
| @@ -178,5 +178,6 @@ enum l2tp_seqmode { · 177 unmodified lines | ||
| 178 | 178 | */ |
| 179 | 179 | #define L2TP_GENL_NAME "l2tp" |
| 180 | 180 | #define L2TP_GENL_VERSION 0x1 |
| 181 | +#define L2TP_GENL_MCGROUP "l2tp" | |
| 181 | 182 | |
| 182 | 183 | #endif /* _UAPI_LINUX_L2TP_H_ */ |
| @@ -40,6 +40,18 @@ static struct genl_family l2tp_nl_family = { · 39 unmodified lines | ||
| 40 | 40 | .netnsok = true, |
| 41 | 41 | }; |
| 42 | 42 | |
| 43 | +static const struct genl_multicast_group l2tp_multicast_group[] = { | |
| 44 | + { | |
| 45 | + .name = L2TP_GENL_MCGROUP, | |
| 46 | + }, | |
| 47 | +}; | |
| 48 | + | |
| 49 | +static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, | |
| 50 | + int flags, struct l2tp_tunnel *tunnel, u8 cmd); | |
| 51 | +static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, | |
| 52 | + int flags, struct l2tp_session *session, | |
| 53 | + u8 cmd); | |
| 54 | + | |
| 43 | 55 | /* Accessed under genl lock */ |
| 44 | 56 | static const struct l2tp_nl_cmd_ops *l2tp_nl_cmd_ops[__L2TP_PWTYPE_MAX]; |
| 45 | 57 | |
| @@ -97,6 +109,52 @@ out: · 51 unmodified lines | ||
| 97 | 109 | return ret; |
| 98 | 110 | } |
| 99 | 111 | |
| 112 | +static int l2tp_tunnel_notify(struct genl_family *family, | |
| 113 | + struct genl_info *info, | |
| 114 | + struct l2tp_tunnel *tunnel, | |
| 115 | + u8 cmd) | |
| 116 | +{ | |
| 117 | + struct sk_buff *msg; | |
| 118 | + int ret; | |
| 119 | + | |
| 120 | + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
| 121 | + if (!msg) | |
| 122 | + return -ENOMEM; | |
| 123 | + | |
| 124 | + ret = l2tp_nl_tunnel_send(msg, info->snd_portid, info->snd_seq, | |
| 125 | + NLM_F_ACK, tunnel, cmd); | |
| 126 | + | |
| 127 | + if (ret >= 0) | |
| 128 | + return genlmsg_multicast_allns(family, msg, 0, 0, GFP_ATOMIC); | |
| 129 | + | |
| 130 | + nlmsg_free(msg); | |
| 131 | + | |
| 132 | + return ret; | |
| 133 | +} | |
| 134 | + | |
| 135 | +static int l2tp_session_notify(struct genl_family *family, | |
| 136 | + struct genl_info *info, | |
| 137 | + struct l2tp_session *session, | |
| 138 | + u8 cmd) | |
| 139 | +{ | |
| 140 | + struct sk_buff *msg; | |
| 141 | + int ret; | |
| 142 | + | |
| 143 | + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
| 144 | + if (!msg) | |
| 145 | + return -ENOMEM; | |
| 146 | + | |
| 147 | + ret = l2tp_nl_session_send(msg, info->snd_portid, info->snd_seq, | |
| 148 | + NLM_F_ACK, session, cmd); | |
| 149 | + | |
| 150 | + if (ret >= 0) | |
| 151 | + return genlmsg_multicast_allns(family, msg, 0, 0, GFP_ATOMIC); | |
| 152 | + | |
| 153 | + nlmsg_free(msg); | |
| 154 | + | |
| 155 | + return ret; | |
| 156 | +} | |
| 157 | + | |
| 100 | 158 | static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info) |
| 101 | 159 | { |
| 102 | 160 | u32 tunnel_id; |
| @@ -188,6 +246,9 @@ static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info · 85 unmodified lines | ||
| 188 | 246 | break; |
| 189 | 247 | } |
| 190 | 248 | |
| 249 | + if (ret >= 0) | |
| 250 | + ret = l2tp_tunnel_notify(&l2tp_nl_family, info, | |
| 251 | + tunnel, L2TP_CMD_TUNNEL_CREATE); | |
| 191 | 252 | out: |
| 192 | 253 | return ret; |
| 193 | 254 | } |
| @@ -211,6 +272,9 @@ static int l2tp_nl_cmd_tunnel_delete(struct sk_buff *skb, struct genl_info *info · 17 unmodified lines | ||
| 211 | 272 | goto out; |
| 212 | 273 | } |
| 213 | 274 | |
| 275 | + l2tp_tunnel_notify(&l2tp_nl_family, info, | |
| 276 | + tunnel, L2TP_CMD_TUNNEL_DELETE); | |
| 277 | + | |
| 214 | 278 | (void) l2tp_tunnel_delete(tunnel); |
| 215 | 279 | |
| 216 | 280 | out: |
| @@ -239,12 +303,15 @@ static int l2tp_nl_cmd_tunnel_modify(struct sk_buff *skb, struct genl_info *info · 22 unmodified lines | ||
| 239 | 303 | if (info->attrs[L2TP_ATTR_DEBUG]) |
| 240 | 304 | tunnel->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); |
| 241 | 305 | |
| 306 | + ret = l2tp_tunnel_notify(&l2tp_nl_family, info, | |
| 307 | + tunnel, L2TP_CMD_TUNNEL_MODIFY); | |
| 308 | + | |
| 242 | 309 | out: |
| 243 | 310 | return ret; |
| 244 | 311 | } |
| 245 | 312 | |
| 246 | 313 | static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int flags, |
| 247 | − struct l2tp_tunnel *tunnel) | |
| 314 | + struct l2tp_tunnel *tunnel, u8 cmd) | |
| 248 | 315 | { |
| 249 | 316 | void *hdr; |
| 250 | 317 | struct nlattr *nest; |
| @@ -254,8 +321,7 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla · 3 unmodified lines | ||
| 254 | 321 | struct ipv6_pinfo *np = NULL; |
| 255 | 322 | #endif |
| 256 | 323 | |
| 257 | − hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, | |
| 258 | − L2TP_CMD_TUNNEL_GET); | |
| 324 | + hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, cmd); | |
| 259 | 325 | if (!hdr) |
| 260 | 326 | return -EMSGSIZE; |
| 261 | 327 | |
| @@ -359,7 +425,7 @@ static int l2tp_nl_cmd_tunnel_get(struct sk_buff *skb, struct genl_info *info) · 97 unmodified lines | ||
| 359 | 425 | } |
| 360 | 426 | |
| 361 | 427 | ret = l2tp_nl_tunnel_send(msg, info->snd_portid, info->snd_seq, |
| 362 | − NLM_F_ACK, tunnel); | |
| 428 | + NLM_F_ACK, tunnel, L2TP_CMD_TUNNEL_GET); | |
| 363 | 429 | if (ret < 0) |
| 364 | 430 | goto err_out; |
| 365 | 431 | |
| @@ -385,7 +451,7 @@ static int l2tp_nl_cmd_tunnel_dump(struct sk_buff *skb, struct netlink_callback · 19 unmodified lines | ||
| 385 | 451 | |
| 386 | 452 | if (l2tp_nl_tunnel_send(skb, NETLINK_CB(cb->skb).portid, |
| 387 | 453 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 388 | − tunnel) <= 0) | |
| 454 | + tunnel, L2TP_CMD_TUNNEL_GET) <= 0) | |
| 389 | 455 | goto out; |
| 390 | 456 | |
| 391 | 457 | ti++; |
| @@ -539,6 +605,13 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf · 147 unmodified lines | ||
| 539 | 605 | ret = (*l2tp_nl_cmd_ops[cfg.pw_type]->session_create)(net, tunnel_id, |
| 540 | 606 | session_id, peer_session_id, &cfg); |
| 541 | 607 | |
| 608 | + if (ret >= 0) { | |
| 609 | + session = l2tp_session_find(net, tunnel, session_id); | |
| 610 | + if (session) | |
| 611 | + ret = l2tp_session_notify(&l2tp_nl_family, info, session, | |
| 612 | + L2TP_CMD_SESSION_CREATE); | |
| 613 | + } | |
| 614 | + | |
| 542 | 615 | out: |
| 543 | 616 | return ret; |
| 544 | 617 | } |
| @@ -555,6 +628,9 @@ static int l2tp_nl_cmd_session_delete(struct sk_buff *skb, struct genl_info *inf · 10 unmodified lines | ||
| 555 | 628 | goto out; |
| 556 | 629 | } |
| 557 | 630 | |
| 631 | + l2tp_session_notify(&l2tp_nl_family, info, | |
| 632 | + session, L2TP_CMD_SESSION_DELETE); | |
| 633 | + | |
| 558 | 634 | pw_type = session->pwtype; |
| 559 | 635 | if (pw_type < __L2TP_PWTYPE_MAX) |
| 560 | 636 | if (l2tp_nl_cmd_ops[pw_type] && l2tp_nl_cmd_ops[pw_type]->session_delete) |
| @@ -601,12 +677,15 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *inf · 40 unmodified lines | ||
| 601 | 677 | if (info->attrs[L2TP_ATTR_MRU]) |
| 602 | 678 | session->mru = nla_get_u16(info->attrs[L2TP_ATTR_MRU]); |
| 603 | 679 | |
| 680 | + ret = l2tp_session_notify(&l2tp_nl_family, info, | |
| 681 | + session, L2TP_CMD_SESSION_MODIFY); | |
| 682 | + | |
| 604 | 683 | out: |
| 605 | 684 | return ret; |
| 606 | 685 | } |
| 607 | 686 | |
| 608 | 687 | static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int flags, |
| 609 | − struct l2tp_session *session) | |
| 688 | + struct l2tp_session *session, u8 cmd) | |
| 610 | 689 | { |
| 611 | 690 | void *hdr; |
| 612 | 691 | struct nlattr *nest; |
| @@ -615,7 +694,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl · 2 unmodified lines | ||
| 615 | 694 | |
| 616 | 695 | sk = tunnel->sock; |
| 617 | 696 | |
| 618 | − hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, L2TP_CMD_SESSION_GET); | |
| 697 | + hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, cmd); | |
| 619 | 698 | if (!hdr) |
| 620 | 699 | return -EMSGSIZE; |
| 621 | 700 | |
| @@ -699,7 +778,7 @@ static int l2tp_nl_cmd_session_get(struct sk_buff *skb, struct genl_info *info) · 77 unmodified lines | ||
| 699 | 778 | } |
| 700 | 779 | |
| 701 | 780 | ret = l2tp_nl_session_send(msg, info->snd_portid, info->snd_seq, |
| 702 | − 0, session); | |
| 781 | + 0, session, L2TP_CMD_SESSION_GET); | |
| 703 | 782 | if (ret < 0) |
| 704 | 783 | goto err_out; |
| 705 | 784 | |
| @@ -737,7 +816,7 @@ static int l2tp_nl_cmd_session_dump(struct sk_buff *skb, struct netlink_callback · 31 unmodified lines | ||
| 737 | 816 | |
| 738 | 817 | if (l2tp_nl_session_send(skb, NETLINK_CB(cb->skb).portid, |
| 739 | 818 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 740 | − session) <= 0) | |
| 819 | + session, L2TP_CMD_SESSION_GET) <= 0) | |
| 741 | 820 | break; |
| 742 | 821 | |
| 743 | 822 | si++; |
| @@ -896,7 +975,9 @@ EXPORT_SYMBOL_GPL(l2tp_nl_unregister_ops); · 152 unmodified lines | ||
| 896 | 975 | static int l2tp_nl_init(void) |
| 897 | 976 | { |
| 898 | 977 | pr_info("L2TP netlink interface\n"); |
| 899 | − return genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops); | |
| 978 | + return genl_register_family_with_ops_groups(&l2tp_nl_family, | |
| 979 | + l2tp_nl_ops, | |
| 980 | + l2tp_multicast_group); | |
| 900 | 981 | } |
| 901 | 982 | |
| 902 | 983 | static void l2tp_nl_cleanup(void) |