Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1 | #include <linux/types.h> |
| 2 | #include <linux/skbuff.h> |
| 3 | #include <linux/socket.h> |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 4 | #include <linux/sysctl.h> |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 5 | #include <linux/net.h> |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/if_arp.h> |
| 8 | #include <linux/ipv6.h> |
| 9 | #include <linux/mpls.h> |
Stephen Rothwell | 4b5edb2 | 2015-03-05 13:37:05 +1100 | [diff] [blame] | 10 | #include <linux/vmalloc.h> |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 11 | #include <net/ip.h> |
| 12 | #include <net/dst.h> |
| 13 | #include <net/sock.h> |
| 14 | #include <net/arp.h> |
| 15 | #include <net/ip_fib.h> |
| 16 | #include <net/netevent.h> |
| 17 | #include <net/netns/generic.h> |
Roopa Prabhu | bf21563 | 2015-07-30 13:34:54 -0700 | [diff] [blame] | 18 | #if IS_ENABLED(CONFIG_IPV6) |
| 19 | #include <net/ipv6.h> |
| 20 | #include <net/addrconf.h> |
| 21 | #endif |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 22 | #include <net/nexthop.h> |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 23 | #include "internal.h" |
| 24 | |
Robert Shearman | 1c78efa | 2015-10-23 06:03:28 -0700 | [diff] [blame^] | 25 | /* Maximum number of labels to look ahead at when selecting a path of |
| 26 | * a multipath route |
| 27 | */ |
| 28 | #define MAX_MP_SELECT_LABELS 4 |
| 29 | |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 30 | static int zero = 0; |
| 31 | static int label_limit = (1 << 20) - 1; |
| 32 | |
Eric W. Biederman | 8de147d | 2015-03-03 19:14:31 -0600 | [diff] [blame] | 33 | static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt, |
| 34 | struct nlmsghdr *nlh, struct net *net, u32 portid, |
| 35 | unsigned int nlm_flags); |
| 36 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 37 | static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index) |
| 38 | { |
| 39 | struct mpls_route *rt = NULL; |
| 40 | |
| 41 | if (index < net->mpls.platform_labels) { |
| 42 | struct mpls_route __rcu **platform_label = |
| 43 | rcu_dereference(net->mpls.platform_label); |
| 44 | rt = rcu_dereference(platform_label[index]); |
| 45 | } |
| 46 | return rt; |
| 47 | } |
| 48 | |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 49 | static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev) |
| 50 | { |
| 51 | return rcu_dereference_rtnl(dev->mpls_ptr); |
| 52 | } |
| 53 | |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 54 | bool mpls_output_possible(const struct net_device *dev) |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 55 | { |
| 56 | return dev && (dev->flags & IFF_UP) && netif_carrier_ok(dev); |
| 57 | } |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 58 | EXPORT_SYMBOL_GPL(mpls_output_possible); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 59 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 60 | static unsigned int mpls_nh_header_size(const struct mpls_nh *nh) |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 61 | { |
| 62 | /* The size of the layer 2.5 labels to be added for this route */ |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 63 | return nh->nh_labels * sizeof(struct mpls_shim_hdr); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 64 | } |
| 65 | |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 66 | unsigned int mpls_dev_mtu(const struct net_device *dev) |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 67 | { |
| 68 | /* The amount of data the layer 2 frame can hold */ |
| 69 | return dev->mtu; |
| 70 | } |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 71 | EXPORT_SYMBOL_GPL(mpls_dev_mtu); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 72 | |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 73 | bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu) |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 74 | { |
| 75 | if (skb->len <= mtu) |
| 76 | return false; |
| 77 | |
| 78 | if (skb_is_gso(skb) && skb_gso_network_seglen(skb) <= mtu) |
| 79 | return false; |
| 80 | |
| 81 | return true; |
| 82 | } |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 83 | EXPORT_SYMBOL_GPL(mpls_pkt_too_big); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 84 | |
Robert Shearman | 1c78efa | 2015-10-23 06:03:28 -0700 | [diff] [blame^] | 85 | static struct mpls_nh *mpls_select_multipath(struct mpls_route *rt, |
| 86 | struct sk_buff *skb, bool bos) |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 87 | { |
Robert Shearman | 1c78efa | 2015-10-23 06:03:28 -0700 | [diff] [blame^] | 88 | struct mpls_entry_decoded dec; |
| 89 | struct mpls_shim_hdr *hdr; |
| 90 | bool eli_seen = false; |
| 91 | int label_index; |
| 92 | int nh_index = 0; |
| 93 | u32 hash = 0; |
| 94 | |
| 95 | /* No need to look further into packet if there's only |
| 96 | * one path |
| 97 | */ |
| 98 | if (rt->rt_nhn == 1) |
| 99 | goto out; |
| 100 | |
| 101 | for (label_index = 0; label_index < MAX_MP_SELECT_LABELS && !bos; |
| 102 | label_index++) { |
| 103 | if (!pskb_may_pull(skb, sizeof(*hdr) * label_index)) |
| 104 | break; |
| 105 | |
| 106 | /* Read and decode the current label */ |
| 107 | hdr = mpls_hdr(skb) + label_index; |
| 108 | dec = mpls_entry_decode(hdr); |
| 109 | |
| 110 | /* RFC6790 - reserved labels MUST NOT be used as keys |
| 111 | * for the load-balancing function |
| 112 | */ |
| 113 | if (likely(dec.label >= MPLS_LABEL_FIRST_UNRESERVED)) { |
| 114 | hash = jhash_1word(dec.label, hash); |
| 115 | |
| 116 | /* The entropy label follows the entropy label |
| 117 | * indicator, so this means that the entropy |
| 118 | * label was just added to the hash - no need to |
| 119 | * go any deeper either in the label stack or in the |
| 120 | * payload |
| 121 | */ |
| 122 | if (eli_seen) |
| 123 | break; |
| 124 | } else if (dec.label == MPLS_LABEL_ENTROPY) { |
| 125 | eli_seen = true; |
| 126 | } |
| 127 | |
| 128 | bos = dec.bos; |
| 129 | if (bos && pskb_may_pull(skb, sizeof(*hdr) * label_index + |
| 130 | sizeof(struct iphdr))) { |
| 131 | const struct iphdr *v4hdr; |
| 132 | |
| 133 | v4hdr = (const struct iphdr *)(mpls_hdr(skb) + |
| 134 | label_index); |
| 135 | if (v4hdr->version == 4) { |
| 136 | hash = jhash_3words(ntohl(v4hdr->saddr), |
| 137 | ntohl(v4hdr->daddr), |
| 138 | v4hdr->protocol, hash); |
| 139 | } else if (v4hdr->version == 6 && |
| 140 | pskb_may_pull(skb, sizeof(*hdr) * label_index + |
| 141 | sizeof(struct ipv6hdr))) { |
| 142 | const struct ipv6hdr *v6hdr; |
| 143 | |
| 144 | v6hdr = (const struct ipv6hdr *)(mpls_hdr(skb) + |
| 145 | label_index); |
| 146 | |
| 147 | hash = __ipv6_addr_jhash(&v6hdr->saddr, hash); |
| 148 | hash = __ipv6_addr_jhash(&v6hdr->daddr, hash); |
| 149 | hash = jhash_1word(v6hdr->nexthdr, hash); |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | nh_index = hash % rt->rt_nhn; |
| 155 | out: |
| 156 | return &rt->rt_nh[nh_index]; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 159 | static bool mpls_egress(struct mpls_route *rt, struct sk_buff *skb, |
| 160 | struct mpls_entry_decoded dec) |
| 161 | { |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 162 | enum mpls_payload_type payload_type; |
| 163 | bool success = false; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 164 | |
Eric W. Biederman | 76fecd8 | 2015-03-12 18:22:59 -0500 | [diff] [blame] | 165 | /* The IPv4 code below accesses through the IPv4 header |
| 166 | * checksum, which is 12 bytes into the packet. |
| 167 | * The IPv6 code below accesses through the IPv6 hop limit |
| 168 | * which is 8 bytes into the packet. |
| 169 | * |
| 170 | * For all supported cases there should always be at least 12 |
| 171 | * bytes of packet data present. The IPv4 header is 20 bytes |
| 172 | * without options and the IPv6 header is always 40 bytes |
| 173 | * long. |
| 174 | */ |
| 175 | if (!pskb_may_pull(skb, 12)) |
| 176 | return false; |
| 177 | |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 178 | payload_type = rt->rt_payload_type; |
| 179 | if (payload_type == MPT_UNSPEC) |
| 180 | payload_type = ip_hdr(skb)->version; |
| 181 | |
| 182 | switch (payload_type) { |
| 183 | case MPT_IPV4: { |
| 184 | struct iphdr *hdr4 = ip_hdr(skb); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 185 | skb->protocol = htons(ETH_P_IP); |
| 186 | csum_replace2(&hdr4->check, |
| 187 | htons(hdr4->ttl << 8), |
| 188 | htons(dec.ttl << 8)); |
| 189 | hdr4->ttl = dec.ttl; |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 190 | success = true; |
| 191 | break; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 192 | } |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 193 | case MPT_IPV6: { |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 194 | struct ipv6hdr *hdr6 = ipv6_hdr(skb); |
| 195 | skb->protocol = htons(ETH_P_IPV6); |
| 196 | hdr6->hop_limit = dec.ttl; |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 197 | success = true; |
| 198 | break; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 199 | } |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 200 | case MPT_UNSPEC: |
| 201 | break; |
| 202 | } |
| 203 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 204 | return success; |
| 205 | } |
| 206 | |
| 207 | static int mpls_forward(struct sk_buff *skb, struct net_device *dev, |
| 208 | struct packet_type *pt, struct net_device *orig_dev) |
| 209 | { |
| 210 | struct net *net = dev_net(dev); |
| 211 | struct mpls_shim_hdr *hdr; |
| 212 | struct mpls_route *rt; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 213 | struct mpls_nh *nh; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 214 | struct mpls_entry_decoded dec; |
| 215 | struct net_device *out_dev; |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 216 | struct mpls_dev *mdev; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 217 | unsigned int hh_len; |
| 218 | unsigned int new_header_size; |
| 219 | unsigned int mtu; |
| 220 | int err; |
| 221 | |
| 222 | /* Careful this entire function runs inside of an rcu critical section */ |
| 223 | |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 224 | mdev = mpls_dev_get(dev); |
Robert Shearman | 37bde79 | 2015-04-22 11:14:38 +0100 | [diff] [blame] | 225 | if (!mdev || !mdev->input_enabled) |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 226 | goto drop; |
| 227 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 228 | if (skb->pkt_type != PACKET_HOST) |
| 229 | goto drop; |
| 230 | |
| 231 | if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) |
| 232 | goto drop; |
| 233 | |
| 234 | if (!pskb_may_pull(skb, sizeof(*hdr))) |
| 235 | goto drop; |
| 236 | |
| 237 | /* Read and decode the label */ |
| 238 | hdr = mpls_hdr(skb); |
| 239 | dec = mpls_entry_decode(hdr); |
| 240 | |
| 241 | /* Pop the label */ |
| 242 | skb_pull(skb, sizeof(*hdr)); |
| 243 | skb_reset_network_header(skb); |
| 244 | |
| 245 | skb_orphan(skb); |
| 246 | |
| 247 | rt = mpls_route_input_rcu(net, dec.label); |
| 248 | if (!rt) |
| 249 | goto drop; |
| 250 | |
Robert Shearman | 1c78efa | 2015-10-23 06:03:28 -0700 | [diff] [blame^] | 251 | nh = mpls_select_multipath(rt, skb, dec.bos); |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 252 | if (!nh) |
| 253 | goto drop; |
| 254 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 255 | /* Find the output device */ |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 256 | out_dev = rcu_dereference(nh->nh_dev); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 257 | if (!mpls_output_possible(out_dev)) |
| 258 | goto drop; |
| 259 | |
| 260 | if (skb_warn_if_lro(skb)) |
| 261 | goto drop; |
| 262 | |
| 263 | skb_forward_csum(skb); |
| 264 | |
| 265 | /* Verify ttl is valid */ |
Eric W. Biederman | aa7da93 | 2015-03-07 16:23:23 -0600 | [diff] [blame] | 266 | if (dec.ttl <= 1) |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 267 | goto drop; |
| 268 | dec.ttl -= 1; |
| 269 | |
| 270 | /* Verify the destination can hold the packet */ |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 271 | new_header_size = mpls_nh_header_size(nh); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 272 | mtu = mpls_dev_mtu(out_dev); |
| 273 | if (mpls_pkt_too_big(skb, mtu - new_header_size)) |
| 274 | goto drop; |
| 275 | |
| 276 | hh_len = LL_RESERVED_SPACE(out_dev); |
| 277 | if (!out_dev->header_ops) |
| 278 | hh_len = 0; |
| 279 | |
| 280 | /* Ensure there is enough space for the headers in the skb */ |
| 281 | if (skb_cow(skb, hh_len + new_header_size)) |
| 282 | goto drop; |
| 283 | |
| 284 | skb->dev = out_dev; |
| 285 | skb->protocol = htons(ETH_P_MPLS_UC); |
| 286 | |
| 287 | if (unlikely(!new_header_size && dec.bos)) { |
| 288 | /* Penultimate hop popping */ |
| 289 | if (!mpls_egress(rt, skb, dec)) |
| 290 | goto drop; |
| 291 | } else { |
| 292 | bool bos; |
| 293 | int i; |
| 294 | skb_push(skb, new_header_size); |
| 295 | skb_reset_network_header(skb); |
| 296 | /* Push the new labels */ |
| 297 | hdr = mpls_hdr(skb); |
| 298 | bos = dec.bos; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 299 | for (i = nh->nh_labels - 1; i >= 0; i--) { |
| 300 | hdr[i] = mpls_entry_encode(nh->nh_label[i], |
| 301 | dec.ttl, 0, bos); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 302 | bos = false; |
| 303 | } |
| 304 | } |
| 305 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 306 | err = neigh_xmit(nh->nh_via_table, out_dev, nh->nh_via, skb); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 307 | if (err) |
| 308 | net_dbg_ratelimited("%s: packet transmission failed: %d\n", |
| 309 | __func__, err); |
| 310 | return 0; |
| 311 | |
| 312 | drop: |
| 313 | kfree_skb(skb); |
| 314 | return NET_RX_DROP; |
| 315 | } |
| 316 | |
| 317 | static struct packet_type mpls_packet_type __read_mostly = { |
| 318 | .type = cpu_to_be16(ETH_P_MPLS_UC), |
| 319 | .func = mpls_forward, |
| 320 | }; |
| 321 | |
Wu Fengguang | f012653 | 2015-03-05 05:33:54 +0800 | [diff] [blame] | 322 | static const struct nla_policy rtm_mpls_policy[RTA_MAX+1] = { |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 323 | [RTA_DST] = { .type = NLA_U32 }, |
| 324 | [RTA_OIF] = { .type = NLA_U32 }, |
| 325 | }; |
| 326 | |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 327 | struct mpls_route_config { |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 328 | u32 rc_protocol; |
| 329 | u32 rc_ifindex; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 330 | u8 rc_via_table; |
| 331 | u8 rc_via_alen; |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 332 | u8 rc_via[MAX_VIA_ALEN]; |
| 333 | u32 rc_label; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 334 | u8 rc_output_labels; |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 335 | u32 rc_output_label[MAX_NEW_LABELS]; |
| 336 | u32 rc_nlflags; |
| 337 | enum mpls_payload_type rc_payload_type; |
| 338 | struct nl_info rc_nlinfo; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 339 | struct rtnexthop *rc_mp; |
| 340 | int rc_mp_len; |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 341 | }; |
| 342 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 343 | static struct mpls_route *mpls_rt_alloc(int num_nh) |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 344 | { |
| 345 | struct mpls_route *rt; |
| 346 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 347 | rt = kzalloc(sizeof(*rt) + (num_nh * sizeof(struct mpls_nh)), |
| 348 | GFP_KERNEL); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 349 | if (rt) |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 350 | rt->rt_nhn = num_nh; |
| 351 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 352 | return rt; |
| 353 | } |
| 354 | |
| 355 | static void mpls_rt_free(struct mpls_route *rt) |
| 356 | { |
| 357 | if (rt) |
| 358 | kfree_rcu(rt, rt_rcu); |
| 359 | } |
| 360 | |
Eric W. Biederman | 8de147d | 2015-03-03 19:14:31 -0600 | [diff] [blame] | 361 | static void mpls_notify_route(struct net *net, unsigned index, |
| 362 | struct mpls_route *old, struct mpls_route *new, |
| 363 | const struct nl_info *info) |
| 364 | { |
| 365 | struct nlmsghdr *nlh = info ? info->nlh : NULL; |
| 366 | unsigned portid = info ? info->portid : 0; |
| 367 | int event = new ? RTM_NEWROUTE : RTM_DELROUTE; |
| 368 | struct mpls_route *rt = new ? new : old; |
| 369 | unsigned nlm_flags = (old && new) ? NLM_F_REPLACE : 0; |
| 370 | /* Ignore reserved labels for now */ |
Robert Shearman | a6affd2 | 2015-08-03 17:50:04 +0100 | [diff] [blame] | 371 | if (rt && (index >= MPLS_LABEL_FIRST_UNRESERVED)) |
Eric W. Biederman | 8de147d | 2015-03-03 19:14:31 -0600 | [diff] [blame] | 372 | rtmsg_lfib(event, index, rt, nlh, net, portid, nlm_flags); |
| 373 | } |
| 374 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 375 | static void mpls_route_update(struct net *net, unsigned index, |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 376 | struct mpls_route *new, |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 377 | const struct nl_info *info) |
| 378 | { |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 379 | struct mpls_route __rcu **platform_label; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 380 | struct mpls_route *rt; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 381 | |
| 382 | ASSERT_RTNL(); |
| 383 | |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 384 | platform_label = rtnl_dereference(net->mpls.platform_label); |
| 385 | rt = rtnl_dereference(platform_label[index]); |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 386 | rcu_assign_pointer(platform_label[index], new); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 387 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 388 | mpls_notify_route(net, index, rt, new, info); |
Eric W. Biederman | 8de147d | 2015-03-03 19:14:31 -0600 | [diff] [blame] | 389 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 390 | /* If we removed a route free it now */ |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 391 | mpls_rt_free(rt); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 392 | } |
| 393 | |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 394 | static unsigned find_free_label(struct net *net) |
| 395 | { |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 396 | struct mpls_route __rcu **platform_label; |
| 397 | size_t platform_labels; |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 398 | unsigned index; |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 399 | |
| 400 | platform_label = rtnl_dereference(net->mpls.platform_label); |
| 401 | platform_labels = net->mpls.platform_labels; |
Robert Shearman | a6affd2 | 2015-08-03 17:50:04 +0100 | [diff] [blame] | 402 | for (index = MPLS_LABEL_FIRST_UNRESERVED; index < platform_labels; |
| 403 | index++) { |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 404 | if (!rtnl_dereference(platform_label[index])) |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 405 | return index; |
| 406 | } |
| 407 | return LABEL_NOT_SPECIFIED; |
| 408 | } |
| 409 | |
Roopa Prabhu | bf21563 | 2015-07-30 13:34:54 -0700 | [diff] [blame] | 410 | #if IS_ENABLED(CONFIG_INET) |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 411 | static struct net_device *inet_fib_lookup_dev(struct net *net, void *addr) |
| 412 | { |
Dan Carpenter | 5a9348b | 2015-08-04 10:44:22 +0300 | [diff] [blame] | 413 | struct net_device *dev; |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 414 | struct rtable *rt; |
| 415 | struct in_addr daddr; |
| 416 | |
| 417 | memcpy(&daddr, addr, sizeof(struct in_addr)); |
| 418 | rt = ip_route_output(net, daddr.s_addr, 0, 0, 0); |
| 419 | if (IS_ERR(rt)) |
Dan Carpenter | 5a9348b | 2015-08-04 10:44:22 +0300 | [diff] [blame] | 420 | return ERR_CAST(rt); |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 421 | |
| 422 | dev = rt->dst.dev; |
| 423 | dev_hold(dev); |
| 424 | |
| 425 | ip_rt_put(rt); |
| 426 | |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 427 | return dev; |
| 428 | } |
Roopa Prabhu | bf21563 | 2015-07-30 13:34:54 -0700 | [diff] [blame] | 429 | #else |
| 430 | static struct net_device *inet_fib_lookup_dev(struct net *net, void *addr) |
| 431 | { |
| 432 | return ERR_PTR(-EAFNOSUPPORT); |
| 433 | } |
| 434 | #endif |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 435 | |
Roopa Prabhu | bf21563 | 2015-07-30 13:34:54 -0700 | [diff] [blame] | 436 | #if IS_ENABLED(CONFIG_IPV6) |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 437 | static struct net_device *inet6_fib_lookup_dev(struct net *net, void *addr) |
| 438 | { |
Dan Carpenter | 5a9348b | 2015-08-04 10:44:22 +0300 | [diff] [blame] | 439 | struct net_device *dev; |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 440 | struct dst_entry *dst; |
| 441 | struct flowi6 fl6; |
Roopa Prabhu | bf21563 | 2015-07-30 13:34:54 -0700 | [diff] [blame] | 442 | int err; |
| 443 | |
| 444 | if (!ipv6_stub) |
| 445 | return ERR_PTR(-EAFNOSUPPORT); |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 446 | |
| 447 | memset(&fl6, 0, sizeof(fl6)); |
| 448 | memcpy(&fl6.daddr, addr, sizeof(struct in6_addr)); |
Roopa Prabhu | bf21563 | 2015-07-30 13:34:54 -0700 | [diff] [blame] | 449 | err = ipv6_stub->ipv6_dst_lookup(net, NULL, &dst, &fl6); |
| 450 | if (err) |
Dan Carpenter | 5a9348b | 2015-08-04 10:44:22 +0300 | [diff] [blame] | 451 | return ERR_PTR(err); |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 452 | |
| 453 | dev = dst->dev; |
| 454 | dev_hold(dev); |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 455 | dst_release(dst); |
| 456 | |
| 457 | return dev; |
| 458 | } |
Roopa Prabhu | bf21563 | 2015-07-30 13:34:54 -0700 | [diff] [blame] | 459 | #else |
| 460 | static struct net_device *inet6_fib_lookup_dev(struct net *net, void *addr) |
| 461 | { |
| 462 | return ERR_PTR(-EAFNOSUPPORT); |
| 463 | } |
| 464 | #endif |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 465 | |
| 466 | static struct net_device *find_outdev(struct net *net, |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 467 | struct mpls_nh *nh, int oif) |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 468 | { |
| 469 | struct net_device *dev = NULL; |
| 470 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 471 | if (!oif) { |
| 472 | switch (nh->nh_via_table) { |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 473 | case NEIGH_ARP_TABLE: |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 474 | dev = inet_fib_lookup_dev(net, nh->nh_via); |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 475 | break; |
| 476 | case NEIGH_ND_TABLE: |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 477 | dev = inet6_fib_lookup_dev(net, nh->nh_via); |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 478 | break; |
| 479 | case NEIGH_LINK_TABLE: |
| 480 | break; |
| 481 | } |
| 482 | } else { |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 483 | dev = dev_get_by_index(net, oif); |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Roopa Prabhu | 3dcb615 | 2015-08-04 06:36:24 -0700 | [diff] [blame] | 486 | if (!dev) |
| 487 | return ERR_PTR(-ENODEV); |
| 488 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 489 | /* The caller is holding rtnl anyways, so release the dev reference */ |
| 490 | dev_put(dev); |
| 491 | |
Roopa Prabhu | 01faef2 | 2015-07-21 09:16:24 -0700 | [diff] [blame] | 492 | return dev; |
| 493 | } |
| 494 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 495 | static int mpls_nh_assign_dev(struct net *net, struct mpls_nh *nh, int oif) |
| 496 | { |
| 497 | struct net_device *dev = NULL; |
| 498 | int err = -ENODEV; |
| 499 | |
| 500 | dev = find_outdev(net, nh, oif); |
| 501 | if (IS_ERR(dev)) { |
| 502 | err = PTR_ERR(dev); |
| 503 | dev = NULL; |
| 504 | goto errout; |
| 505 | } |
| 506 | |
| 507 | /* Ensure this is a supported device */ |
| 508 | err = -EINVAL; |
| 509 | if (!mpls_dev_get(dev)) |
| 510 | goto errout; |
| 511 | |
| 512 | RCU_INIT_POINTER(nh->nh_dev, dev); |
| 513 | |
| 514 | return 0; |
| 515 | |
| 516 | errout: |
| 517 | return err; |
| 518 | } |
| 519 | |
| 520 | static int mpls_nh_build_from_cfg(struct mpls_route_config *cfg, |
| 521 | struct mpls_route *rt) |
| 522 | { |
| 523 | struct net *net = cfg->rc_nlinfo.nl_net; |
| 524 | struct mpls_nh *nh = rt->rt_nh; |
| 525 | int err; |
| 526 | int i; |
| 527 | |
| 528 | if (!nh) |
| 529 | return -ENOMEM; |
| 530 | |
| 531 | err = -EINVAL; |
| 532 | /* Ensure only a supported number of labels are present */ |
| 533 | if (cfg->rc_output_labels > MAX_NEW_LABELS) |
| 534 | goto errout; |
| 535 | |
| 536 | nh->nh_labels = cfg->rc_output_labels; |
| 537 | for (i = 0; i < nh->nh_labels; i++) |
| 538 | nh->nh_label[i] = cfg->rc_output_label[i]; |
| 539 | |
| 540 | nh->nh_via_table = cfg->rc_via_table; |
| 541 | memcpy(nh->nh_via, cfg->rc_via, cfg->rc_via_alen); |
| 542 | nh->nh_via_alen = cfg->rc_via_alen; |
| 543 | |
| 544 | err = mpls_nh_assign_dev(net, nh, cfg->rc_ifindex); |
| 545 | if (err) |
| 546 | goto errout; |
| 547 | |
| 548 | return 0; |
| 549 | |
| 550 | errout: |
| 551 | return err; |
| 552 | } |
| 553 | |
| 554 | static int mpls_nh_build(struct net *net, struct mpls_nh *nh, |
| 555 | int oif, struct nlattr *via, struct nlattr *newdst) |
| 556 | { |
| 557 | int err = -ENOMEM; |
| 558 | |
| 559 | if (!nh) |
| 560 | goto errout; |
| 561 | |
| 562 | if (newdst) { |
| 563 | err = nla_get_labels(newdst, MAX_NEW_LABELS, |
| 564 | &nh->nh_labels, nh->nh_label); |
| 565 | if (err) |
| 566 | goto errout; |
| 567 | } |
| 568 | |
| 569 | err = nla_get_via(via, &nh->nh_via_alen, &nh->nh_via_table, |
| 570 | nh->nh_via); |
| 571 | if (err) |
| 572 | goto errout; |
| 573 | |
| 574 | err = mpls_nh_assign_dev(net, nh, oif); |
| 575 | if (err) |
| 576 | goto errout; |
| 577 | |
| 578 | return 0; |
| 579 | |
| 580 | errout: |
| 581 | return err; |
| 582 | } |
| 583 | |
| 584 | static int mpls_count_nexthops(struct rtnexthop *rtnh, int len) |
| 585 | { |
| 586 | int nhs = 0; |
| 587 | int remaining = len; |
| 588 | |
| 589 | while (rtnh_ok(rtnh, remaining)) { |
| 590 | nhs++; |
| 591 | rtnh = rtnh_next(rtnh, &remaining); |
| 592 | } |
| 593 | |
| 594 | /* leftover implies invalid nexthop configuration, discard it */ |
| 595 | return remaining > 0 ? 0 : nhs; |
| 596 | } |
| 597 | |
| 598 | static int mpls_nh_build_multi(struct mpls_route_config *cfg, |
| 599 | struct mpls_route *rt) |
| 600 | { |
| 601 | struct rtnexthop *rtnh = cfg->rc_mp; |
| 602 | struct nlattr *nla_via, *nla_newdst; |
| 603 | int remaining = cfg->rc_mp_len; |
| 604 | int nhs = 0; |
| 605 | int err = 0; |
| 606 | |
| 607 | change_nexthops(rt) { |
| 608 | int attrlen; |
| 609 | |
| 610 | nla_via = NULL; |
| 611 | nla_newdst = NULL; |
| 612 | |
| 613 | err = -EINVAL; |
| 614 | if (!rtnh_ok(rtnh, remaining)) |
| 615 | goto errout; |
| 616 | |
Robert Shearman | 1c78efa | 2015-10-23 06:03:28 -0700 | [diff] [blame^] | 617 | /* neither weighted multipath nor any flags |
| 618 | * are supported |
| 619 | */ |
| 620 | if (rtnh->rtnh_hops || rtnh->rtnh_flags) |
| 621 | goto errout; |
| 622 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 623 | attrlen = rtnh_attrlen(rtnh); |
| 624 | if (attrlen > 0) { |
| 625 | struct nlattr *attrs = rtnh_attrs(rtnh); |
| 626 | |
| 627 | nla_via = nla_find(attrs, attrlen, RTA_VIA); |
| 628 | nla_newdst = nla_find(attrs, attrlen, RTA_NEWDST); |
| 629 | } |
| 630 | |
| 631 | if (!nla_via) |
| 632 | goto errout; |
| 633 | |
| 634 | err = mpls_nh_build(cfg->rc_nlinfo.nl_net, nh, |
| 635 | rtnh->rtnh_ifindex, nla_via, |
| 636 | nla_newdst); |
| 637 | if (err) |
| 638 | goto errout; |
| 639 | |
| 640 | rtnh = rtnh_next(rtnh, &remaining); |
| 641 | nhs++; |
| 642 | } endfor_nexthops(rt); |
| 643 | |
| 644 | rt->rt_nhn = nhs; |
| 645 | |
| 646 | return 0; |
| 647 | |
| 648 | errout: |
| 649 | return err; |
| 650 | } |
| 651 | |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 652 | static int mpls_route_add(struct mpls_route_config *cfg) |
| 653 | { |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 654 | struct mpls_route __rcu **platform_label; |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 655 | struct net *net = cfg->rc_nlinfo.nl_net; |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 656 | struct mpls_route *rt, *old; |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 657 | int err = -EINVAL; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 658 | unsigned index; |
| 659 | int nhs = 1; /* default to one nexthop */ |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 660 | |
| 661 | index = cfg->rc_label; |
| 662 | |
| 663 | /* If a label was not specified during insert pick one */ |
| 664 | if ((index == LABEL_NOT_SPECIFIED) && |
| 665 | (cfg->rc_nlflags & NLM_F_CREATE)) { |
| 666 | index = find_free_label(net); |
| 667 | } |
| 668 | |
Robert Shearman | a6affd2 | 2015-08-03 17:50:04 +0100 | [diff] [blame] | 669 | /* Reserved labels may not be set */ |
| 670 | if (index < MPLS_LABEL_FIRST_UNRESERVED) |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 671 | goto errout; |
| 672 | |
| 673 | /* The full 20 bit range may not be supported. */ |
| 674 | if (index >= net->mpls.platform_labels) |
| 675 | goto errout; |
| 676 | |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 677 | /* Append makes no sense with mpls */ |
Eric W. Biederman | 0f7bbd5 | 2015-03-07 16:22:40 -0600 | [diff] [blame] | 678 | err = -EOPNOTSUPP; |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 679 | if (cfg->rc_nlflags & NLM_F_APPEND) |
| 680 | goto errout; |
| 681 | |
| 682 | err = -EEXIST; |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 683 | platform_label = rtnl_dereference(net->mpls.platform_label); |
| 684 | old = rtnl_dereference(platform_label[index]); |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 685 | if ((cfg->rc_nlflags & NLM_F_EXCL) && old) |
| 686 | goto errout; |
| 687 | |
| 688 | err = -EEXIST; |
| 689 | if (!(cfg->rc_nlflags & NLM_F_REPLACE) && old) |
| 690 | goto errout; |
| 691 | |
| 692 | err = -ENOENT; |
| 693 | if (!(cfg->rc_nlflags & NLM_F_CREATE) && !old) |
| 694 | goto errout; |
| 695 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 696 | if (cfg->rc_mp) { |
| 697 | err = -EINVAL; |
| 698 | nhs = mpls_count_nexthops(cfg->rc_mp, cfg->rc_mp_len); |
| 699 | if (nhs == 0) |
| 700 | goto errout; |
| 701 | } |
| 702 | |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 703 | err = -ENOMEM; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 704 | rt = mpls_rt_alloc(nhs); |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 705 | if (!rt) |
| 706 | goto errout; |
| 707 | |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 708 | rt->rt_protocol = cfg->rc_protocol; |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 709 | rt->rt_payload_type = cfg->rc_payload_type; |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 710 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 711 | if (cfg->rc_mp) |
| 712 | err = mpls_nh_build_multi(cfg, rt); |
| 713 | else |
| 714 | err = mpls_nh_build_from_cfg(cfg, rt); |
| 715 | if (err) |
| 716 | goto freert; |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 717 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 718 | mpls_route_update(net, index, rt, &cfg->rc_nlinfo); |
| 719 | |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 720 | return 0; |
| 721 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 722 | freert: |
| 723 | mpls_rt_free(rt); |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 724 | errout: |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 725 | return err; |
| 726 | } |
| 727 | |
| 728 | static int mpls_route_del(struct mpls_route_config *cfg) |
| 729 | { |
| 730 | struct net *net = cfg->rc_nlinfo.nl_net; |
| 731 | unsigned index; |
| 732 | int err = -EINVAL; |
| 733 | |
| 734 | index = cfg->rc_label; |
| 735 | |
Robert Shearman | a6affd2 | 2015-08-03 17:50:04 +0100 | [diff] [blame] | 736 | /* Reserved labels may not be removed */ |
| 737 | if (index < MPLS_LABEL_FIRST_UNRESERVED) |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 738 | goto errout; |
| 739 | |
| 740 | /* The full 20 bit range may not be supported */ |
| 741 | if (index >= net->mpls.platform_labels) |
| 742 | goto errout; |
| 743 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 744 | mpls_route_update(net, index, NULL, &cfg->rc_nlinfo); |
Eric W. Biederman | a251992 | 2015-03-03 19:12:40 -0600 | [diff] [blame] | 745 | |
| 746 | err = 0; |
| 747 | errout: |
| 748 | return err; |
| 749 | } |
| 750 | |
Robert Shearman | 37bde79 | 2015-04-22 11:14:38 +0100 | [diff] [blame] | 751 | #define MPLS_PERDEV_SYSCTL_OFFSET(field) \ |
| 752 | (&((struct mpls_dev *)0)->field) |
| 753 | |
| 754 | static const struct ctl_table mpls_dev_table[] = { |
| 755 | { |
| 756 | .procname = "input", |
| 757 | .maxlen = sizeof(int), |
| 758 | .mode = 0644, |
| 759 | .proc_handler = proc_dointvec, |
| 760 | .data = MPLS_PERDEV_SYSCTL_OFFSET(input_enabled), |
| 761 | }, |
| 762 | { } |
| 763 | }; |
| 764 | |
| 765 | static int mpls_dev_sysctl_register(struct net_device *dev, |
| 766 | struct mpls_dev *mdev) |
| 767 | { |
| 768 | char path[sizeof("net/mpls/conf/") + IFNAMSIZ]; |
| 769 | struct ctl_table *table; |
| 770 | int i; |
| 771 | |
| 772 | table = kmemdup(&mpls_dev_table, sizeof(mpls_dev_table), GFP_KERNEL); |
| 773 | if (!table) |
| 774 | goto out; |
| 775 | |
| 776 | /* Table data contains only offsets relative to the base of |
| 777 | * the mdev at this point, so make them absolute. |
| 778 | */ |
| 779 | for (i = 0; i < ARRAY_SIZE(mpls_dev_table); i++) |
| 780 | table[i].data = (char *)mdev + (uintptr_t)table[i].data; |
| 781 | |
| 782 | snprintf(path, sizeof(path), "net/mpls/conf/%s", dev->name); |
| 783 | |
| 784 | mdev->sysctl = register_net_sysctl(dev_net(dev), path, table); |
| 785 | if (!mdev->sysctl) |
| 786 | goto free; |
| 787 | |
| 788 | return 0; |
| 789 | |
| 790 | free: |
| 791 | kfree(table); |
| 792 | out: |
| 793 | return -ENOBUFS; |
| 794 | } |
| 795 | |
| 796 | static void mpls_dev_sysctl_unregister(struct mpls_dev *mdev) |
| 797 | { |
| 798 | struct ctl_table *table; |
| 799 | |
| 800 | table = mdev->sysctl->ctl_table_arg; |
| 801 | unregister_net_sysctl_table(mdev->sysctl); |
| 802 | kfree(table); |
| 803 | } |
| 804 | |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 805 | static struct mpls_dev *mpls_add_dev(struct net_device *dev) |
| 806 | { |
| 807 | struct mpls_dev *mdev; |
| 808 | int err = -ENOMEM; |
| 809 | |
| 810 | ASSERT_RTNL(); |
| 811 | |
| 812 | mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); |
| 813 | if (!mdev) |
| 814 | return ERR_PTR(err); |
| 815 | |
Robert Shearman | 37bde79 | 2015-04-22 11:14:38 +0100 | [diff] [blame] | 816 | err = mpls_dev_sysctl_register(dev, mdev); |
| 817 | if (err) |
| 818 | goto free; |
| 819 | |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 820 | rcu_assign_pointer(dev->mpls_ptr, mdev); |
| 821 | |
| 822 | return mdev; |
Robert Shearman | 37bde79 | 2015-04-22 11:14:38 +0100 | [diff] [blame] | 823 | |
| 824 | free: |
| 825 | kfree(mdev); |
| 826 | return ERR_PTR(err); |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 827 | } |
| 828 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 829 | static void mpls_ifdown(struct net_device *dev) |
| 830 | { |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 831 | struct mpls_route __rcu **platform_label; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 832 | struct net *net = dev_net(dev); |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 833 | struct mpls_dev *mdev; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 834 | unsigned index; |
| 835 | |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 836 | platform_label = rtnl_dereference(net->mpls.platform_label); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 837 | for (index = 0; index < net->mpls.platform_labels; index++) { |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 838 | struct mpls_route *rt = rtnl_dereference(platform_label[index]); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 839 | if (!rt) |
| 840 | continue; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 841 | for_nexthops(rt) { |
| 842 | if (rtnl_dereference(nh->nh_dev) != dev) |
| 843 | continue; |
| 844 | nh->nh_dev = NULL; |
| 845 | } endfor_nexthops(rt); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 846 | } |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 847 | |
| 848 | mdev = mpls_dev_get(dev); |
| 849 | if (!mdev) |
| 850 | return; |
| 851 | |
Robert Shearman | 37bde79 | 2015-04-22 11:14:38 +0100 | [diff] [blame] | 852 | mpls_dev_sysctl_unregister(mdev); |
| 853 | |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 854 | RCU_INIT_POINTER(dev->mpls_ptr, NULL); |
| 855 | |
Robert Shearman | 25cc8f0 | 2015-06-05 18:54:45 +0100 | [diff] [blame] | 856 | kfree_rcu(mdev, rcu); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | static int mpls_dev_notify(struct notifier_block *this, unsigned long event, |
| 860 | void *ptr) |
| 861 | { |
| 862 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 863 | struct mpls_dev *mdev; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 864 | |
| 865 | switch(event) { |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 866 | case NETDEV_REGISTER: |
| 867 | /* For now just support ethernet devices */ |
| 868 | if ((dev->type == ARPHRD_ETHER) || |
| 869 | (dev->type == ARPHRD_LOOPBACK)) { |
| 870 | mdev = mpls_add_dev(dev); |
| 871 | if (IS_ERR(mdev)) |
| 872 | return notifier_from_errno(PTR_ERR(mdev)); |
| 873 | } |
| 874 | break; |
| 875 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 876 | case NETDEV_UNREGISTER: |
| 877 | mpls_ifdown(dev); |
| 878 | break; |
Robert Shearman | 0fae3bf | 2015-06-11 19:58:26 +0100 | [diff] [blame] | 879 | case NETDEV_CHANGENAME: |
| 880 | mdev = mpls_dev_get(dev); |
| 881 | if (mdev) { |
| 882 | int err; |
| 883 | |
| 884 | mpls_dev_sysctl_unregister(mdev); |
| 885 | err = mpls_dev_sysctl_register(dev, mdev); |
| 886 | if (err) |
| 887 | return notifier_from_errno(err); |
| 888 | } |
| 889 | break; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 890 | } |
| 891 | return NOTIFY_OK; |
| 892 | } |
| 893 | |
| 894 | static struct notifier_block mpls_dev_notifier = { |
| 895 | .notifier_call = mpls_dev_notify, |
| 896 | }; |
| 897 | |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 898 | static int nla_put_via(struct sk_buff *skb, |
Eric W. Biederman | b79bda3 | 2015-03-07 16:25:56 -0600 | [diff] [blame] | 899 | u8 table, const void *addr, int alen) |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 900 | { |
Eric W. Biederman | b79bda3 | 2015-03-07 16:25:56 -0600 | [diff] [blame] | 901 | static const int table_to_family[NEIGH_NR_TABLES + 1] = { |
| 902 | AF_INET, AF_INET6, AF_DECnet, AF_PACKET, |
| 903 | }; |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 904 | struct nlattr *nla; |
| 905 | struct rtvia *via; |
Eric W. Biederman | b79bda3 | 2015-03-07 16:25:56 -0600 | [diff] [blame] | 906 | int family = AF_UNSPEC; |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 907 | |
| 908 | nla = nla_reserve(skb, RTA_VIA, alen + 2); |
| 909 | if (!nla) |
| 910 | return -EMSGSIZE; |
| 911 | |
Eric W. Biederman | b79bda3 | 2015-03-07 16:25:56 -0600 | [diff] [blame] | 912 | if (table <= NEIGH_NR_TABLES) |
| 913 | family = table_to_family[table]; |
| 914 | |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 915 | via = nla_data(nla); |
| 916 | via->rtvia_family = family; |
| 917 | memcpy(via->rtvia_addr, addr, alen); |
| 918 | return 0; |
| 919 | } |
| 920 | |
Eric W. Biederman | 966bae3 | 2015-03-03 19:13:19 -0600 | [diff] [blame] | 921 | int nla_put_labels(struct sk_buff *skb, int attrtype, |
| 922 | u8 labels, const u32 label[]) |
| 923 | { |
| 924 | struct nlattr *nla; |
| 925 | struct mpls_shim_hdr *nla_label; |
| 926 | bool bos; |
| 927 | int i; |
| 928 | nla = nla_reserve(skb, attrtype, labels*4); |
| 929 | if (!nla) |
| 930 | return -EMSGSIZE; |
| 931 | |
| 932 | nla_label = nla_data(nla); |
| 933 | bos = true; |
| 934 | for (i = labels - 1; i >= 0; i--) { |
| 935 | nla_label[i] = mpls_entry_encode(label[i], 0, 0, bos); |
| 936 | bos = false; |
| 937 | } |
| 938 | |
| 939 | return 0; |
| 940 | } |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 941 | EXPORT_SYMBOL_GPL(nla_put_labels); |
Eric W. Biederman | 966bae3 | 2015-03-03 19:13:19 -0600 | [diff] [blame] | 942 | |
| 943 | int nla_get_labels(const struct nlattr *nla, |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 944 | u32 max_labels, u8 *labels, u32 label[]) |
Eric W. Biederman | 966bae3 | 2015-03-03 19:13:19 -0600 | [diff] [blame] | 945 | { |
| 946 | unsigned len = nla_len(nla); |
| 947 | unsigned nla_labels; |
| 948 | struct mpls_shim_hdr *nla_label; |
| 949 | bool bos; |
| 950 | int i; |
| 951 | |
| 952 | /* len needs to be an even multiple of 4 (the label size) */ |
| 953 | if (len & 3) |
| 954 | return -EINVAL; |
| 955 | |
| 956 | /* Limit the number of new labels allowed */ |
| 957 | nla_labels = len/4; |
| 958 | if (nla_labels > max_labels) |
| 959 | return -EINVAL; |
| 960 | |
| 961 | nla_label = nla_data(nla); |
| 962 | bos = true; |
| 963 | for (i = nla_labels - 1; i >= 0; i--, bos = false) { |
| 964 | struct mpls_entry_decoded dec; |
| 965 | dec = mpls_entry_decode(nla_label + i); |
| 966 | |
| 967 | /* Ensure the bottom of stack flag is properly set |
| 968 | * and ttl and tc are both clear. |
| 969 | */ |
| 970 | if ((dec.bos != bos) || dec.ttl || dec.tc) |
| 971 | return -EINVAL; |
| 972 | |
Robert Shearman | 5a9ab01 | 2015-04-22 11:14:39 +0100 | [diff] [blame] | 973 | switch (dec.label) { |
Tom Herbert | 78f5b89 | 2015-05-07 08:08:51 -0700 | [diff] [blame] | 974 | case MPLS_LABEL_IMPLNULL: |
Robert Shearman | 5a9ab01 | 2015-04-22 11:14:39 +0100 | [diff] [blame] | 975 | /* RFC3032: This is a label that an LSR may |
| 976 | * assign and distribute, but which never |
| 977 | * actually appears in the encapsulation. |
| 978 | */ |
| 979 | return -EINVAL; |
| 980 | } |
| 981 | |
Eric W. Biederman | 966bae3 | 2015-03-03 19:13:19 -0600 | [diff] [blame] | 982 | label[i] = dec.label; |
| 983 | } |
| 984 | *labels = nla_labels; |
| 985 | return 0; |
| 986 | } |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 987 | EXPORT_SYMBOL_GPL(nla_get_labels); |
Eric W. Biederman | 966bae3 | 2015-03-03 19:13:19 -0600 | [diff] [blame] | 988 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 989 | int nla_get_via(const struct nlattr *nla, u8 *via_alen, |
| 990 | u8 *via_table, u8 via_addr[]) |
| 991 | { |
| 992 | struct rtvia *via = nla_data(nla); |
| 993 | int err = -EINVAL; |
| 994 | int alen; |
| 995 | |
| 996 | if (nla_len(nla) < offsetof(struct rtvia, rtvia_addr)) |
| 997 | goto errout; |
| 998 | alen = nla_len(nla) - |
| 999 | offsetof(struct rtvia, rtvia_addr); |
| 1000 | if (alen > MAX_VIA_ALEN) |
| 1001 | goto errout; |
| 1002 | |
| 1003 | /* Validate the address family */ |
| 1004 | switch (via->rtvia_family) { |
| 1005 | case AF_PACKET: |
| 1006 | *via_table = NEIGH_LINK_TABLE; |
| 1007 | break; |
| 1008 | case AF_INET: |
| 1009 | *via_table = NEIGH_ARP_TABLE; |
| 1010 | if (alen != 4) |
| 1011 | goto errout; |
| 1012 | break; |
| 1013 | case AF_INET6: |
| 1014 | *via_table = NEIGH_ND_TABLE; |
| 1015 | if (alen != 16) |
| 1016 | goto errout; |
| 1017 | break; |
| 1018 | default: |
| 1019 | /* Unsupported address family */ |
| 1020 | goto errout; |
| 1021 | } |
| 1022 | |
| 1023 | memcpy(via_addr, via->rtvia_addr, alen); |
| 1024 | *via_alen = alen; |
| 1025 | err = 0; |
| 1026 | |
| 1027 | errout: |
| 1028 | return err; |
| 1029 | } |
| 1030 | |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1031 | static int rtm_to_route_config(struct sk_buff *skb, struct nlmsghdr *nlh, |
| 1032 | struct mpls_route_config *cfg) |
| 1033 | { |
| 1034 | struct rtmsg *rtm; |
| 1035 | struct nlattr *tb[RTA_MAX+1]; |
| 1036 | int index; |
| 1037 | int err; |
| 1038 | |
| 1039 | err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_mpls_policy); |
| 1040 | if (err < 0) |
| 1041 | goto errout; |
| 1042 | |
| 1043 | err = -EINVAL; |
| 1044 | rtm = nlmsg_data(nlh); |
| 1045 | memset(cfg, 0, sizeof(*cfg)); |
| 1046 | |
| 1047 | if (rtm->rtm_family != AF_MPLS) |
| 1048 | goto errout; |
| 1049 | if (rtm->rtm_dst_len != 20) |
| 1050 | goto errout; |
| 1051 | if (rtm->rtm_src_len != 0) |
| 1052 | goto errout; |
| 1053 | if (rtm->rtm_tos != 0) |
| 1054 | goto errout; |
| 1055 | if (rtm->rtm_table != RT_TABLE_MAIN) |
| 1056 | goto errout; |
| 1057 | /* Any value is acceptable for rtm_protocol */ |
| 1058 | |
| 1059 | /* As mpls uses destination specific addresses |
| 1060 | * (or source specific address in the case of multicast) |
| 1061 | * all addresses have universal scope. |
| 1062 | */ |
| 1063 | if (rtm->rtm_scope != RT_SCOPE_UNIVERSE) |
| 1064 | goto errout; |
| 1065 | if (rtm->rtm_type != RTN_UNICAST) |
| 1066 | goto errout; |
| 1067 | if (rtm->rtm_flags != 0) |
| 1068 | goto errout; |
| 1069 | |
| 1070 | cfg->rc_label = LABEL_NOT_SPECIFIED; |
| 1071 | cfg->rc_protocol = rtm->rtm_protocol; |
| 1072 | cfg->rc_nlflags = nlh->nlmsg_flags; |
| 1073 | cfg->rc_nlinfo.portid = NETLINK_CB(skb).portid; |
| 1074 | cfg->rc_nlinfo.nlh = nlh; |
| 1075 | cfg->rc_nlinfo.nl_net = sock_net(skb->sk); |
| 1076 | |
| 1077 | for (index = 0; index <= RTA_MAX; index++) { |
| 1078 | struct nlattr *nla = tb[index]; |
| 1079 | if (!nla) |
| 1080 | continue; |
| 1081 | |
| 1082 | switch(index) { |
| 1083 | case RTA_OIF: |
| 1084 | cfg->rc_ifindex = nla_get_u32(nla); |
| 1085 | break; |
| 1086 | case RTA_NEWDST: |
| 1087 | if (nla_get_labels(nla, MAX_NEW_LABELS, |
| 1088 | &cfg->rc_output_labels, |
| 1089 | cfg->rc_output_label)) |
| 1090 | goto errout; |
| 1091 | break; |
| 1092 | case RTA_DST: |
| 1093 | { |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1094 | u8 label_count; |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1095 | if (nla_get_labels(nla, 1, &label_count, |
| 1096 | &cfg->rc_label)) |
| 1097 | goto errout; |
| 1098 | |
Robert Shearman | a6affd2 | 2015-08-03 17:50:04 +0100 | [diff] [blame] | 1099 | /* Reserved labels may not be set */ |
| 1100 | if (cfg->rc_label < MPLS_LABEL_FIRST_UNRESERVED) |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1101 | goto errout; |
| 1102 | |
| 1103 | break; |
| 1104 | } |
| 1105 | case RTA_VIA: |
| 1106 | { |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1107 | if (nla_get_via(nla, &cfg->rc_via_alen, |
| 1108 | &cfg->rc_via_table, cfg->rc_via)) |
Robert Shearman | f8d54af | 2015-03-06 10:47:00 +0000 | [diff] [blame] | 1109 | goto errout; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1110 | break; |
| 1111 | } |
| 1112 | case RTA_MULTIPATH: |
| 1113 | { |
| 1114 | cfg->rc_mp = nla_data(nla); |
| 1115 | cfg->rc_mp_len = nla_len(nla); |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1116 | break; |
| 1117 | } |
| 1118 | default: |
| 1119 | /* Unsupported attribute */ |
| 1120 | goto errout; |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | err = 0; |
| 1125 | errout: |
| 1126 | return err; |
| 1127 | } |
| 1128 | |
| 1129 | static int mpls_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh) |
| 1130 | { |
| 1131 | struct mpls_route_config cfg; |
| 1132 | int err; |
| 1133 | |
| 1134 | err = rtm_to_route_config(skb, nlh, &cfg); |
| 1135 | if (err < 0) |
| 1136 | return err; |
| 1137 | |
| 1138 | return mpls_route_del(&cfg); |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | static int mpls_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh) |
| 1143 | { |
| 1144 | struct mpls_route_config cfg; |
| 1145 | int err; |
| 1146 | |
| 1147 | err = rtm_to_route_config(skb, nlh, &cfg); |
| 1148 | if (err < 0) |
| 1149 | return err; |
| 1150 | |
| 1151 | return mpls_route_add(&cfg); |
| 1152 | } |
| 1153 | |
| 1154 | static int mpls_dump_route(struct sk_buff *skb, u32 portid, u32 seq, int event, |
| 1155 | u32 label, struct mpls_route *rt, int flags) |
| 1156 | { |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1157 | struct net_device *dev; |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1158 | struct nlmsghdr *nlh; |
| 1159 | struct rtmsg *rtm; |
| 1160 | |
| 1161 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(*rtm), flags); |
| 1162 | if (nlh == NULL) |
| 1163 | return -EMSGSIZE; |
| 1164 | |
| 1165 | rtm = nlmsg_data(nlh); |
| 1166 | rtm->rtm_family = AF_MPLS; |
| 1167 | rtm->rtm_dst_len = 20; |
| 1168 | rtm->rtm_src_len = 0; |
| 1169 | rtm->rtm_tos = 0; |
| 1170 | rtm->rtm_table = RT_TABLE_MAIN; |
| 1171 | rtm->rtm_protocol = rt->rt_protocol; |
| 1172 | rtm->rtm_scope = RT_SCOPE_UNIVERSE; |
| 1173 | rtm->rtm_type = RTN_UNICAST; |
| 1174 | rtm->rtm_flags = 0; |
| 1175 | |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1176 | if (nla_put_labels(skb, RTA_DST, 1, &label)) |
| 1177 | goto nla_put_failure; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1178 | if (rt->rt_nhn == 1) { |
| 1179 | struct mpls_nh *nh = rt->rt_nh; |
| 1180 | |
| 1181 | if (nh->nh_labels && |
| 1182 | nla_put_labels(skb, RTA_NEWDST, nh->nh_labels, |
| 1183 | nh->nh_label)) |
| 1184 | goto nla_put_failure; |
| 1185 | if (nla_put_via(skb, nh->nh_via_table, nh->nh_via, |
| 1186 | nh->nh_via_alen)) |
| 1187 | goto nla_put_failure; |
| 1188 | dev = rtnl_dereference(nh->nh_dev); |
| 1189 | if (dev && nla_put_u32(skb, RTA_OIF, dev->ifindex)) |
| 1190 | goto nla_put_failure; |
| 1191 | } else { |
| 1192 | struct rtnexthop *rtnh; |
| 1193 | struct nlattr *mp; |
| 1194 | |
| 1195 | mp = nla_nest_start(skb, RTA_MULTIPATH); |
| 1196 | if (!mp) |
| 1197 | goto nla_put_failure; |
| 1198 | |
| 1199 | for_nexthops(rt) { |
| 1200 | rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh)); |
| 1201 | if (!rtnh) |
| 1202 | goto nla_put_failure; |
| 1203 | |
| 1204 | dev = rtnl_dereference(nh->nh_dev); |
| 1205 | if (dev) |
| 1206 | rtnh->rtnh_ifindex = dev->ifindex; |
| 1207 | if (nh->nh_labels && nla_put_labels(skb, RTA_NEWDST, |
| 1208 | nh->nh_labels, |
| 1209 | nh->nh_label)) |
| 1210 | goto nla_put_failure; |
| 1211 | if (nla_put_via(skb, nh->nh_via_table, |
| 1212 | nh->nh_via, |
| 1213 | nh->nh_via_alen)) |
| 1214 | goto nla_put_failure; |
| 1215 | |
| 1216 | /* length of rtnetlink header + attributes */ |
| 1217 | rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh; |
| 1218 | } endfor_nexthops(rt); |
| 1219 | |
| 1220 | nla_nest_end(skb, mp); |
| 1221 | } |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1222 | |
| 1223 | nlmsg_end(skb, nlh); |
| 1224 | return 0; |
| 1225 | |
| 1226 | nla_put_failure: |
| 1227 | nlmsg_cancel(skb, nlh); |
| 1228 | return -EMSGSIZE; |
| 1229 | } |
| 1230 | |
| 1231 | static int mpls_dump_routes(struct sk_buff *skb, struct netlink_callback *cb) |
| 1232 | { |
| 1233 | struct net *net = sock_net(skb->sk); |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1234 | struct mpls_route __rcu **platform_label; |
| 1235 | size_t platform_labels; |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1236 | unsigned int index; |
| 1237 | |
| 1238 | ASSERT_RTNL(); |
| 1239 | |
| 1240 | index = cb->args[0]; |
Robert Shearman | a6affd2 | 2015-08-03 17:50:04 +0100 | [diff] [blame] | 1241 | if (index < MPLS_LABEL_FIRST_UNRESERVED) |
| 1242 | index = MPLS_LABEL_FIRST_UNRESERVED; |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1243 | |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1244 | platform_label = rtnl_dereference(net->mpls.platform_label); |
| 1245 | platform_labels = net->mpls.platform_labels; |
| 1246 | for (; index < platform_labels; index++) { |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1247 | struct mpls_route *rt; |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1248 | rt = rtnl_dereference(platform_label[index]); |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1249 | if (!rt) |
| 1250 | continue; |
| 1251 | |
| 1252 | if (mpls_dump_route(skb, NETLINK_CB(cb->skb).portid, |
| 1253 | cb->nlh->nlmsg_seq, RTM_NEWROUTE, |
| 1254 | index, rt, NLM_F_MULTI) < 0) |
| 1255 | break; |
| 1256 | } |
| 1257 | cb->args[0] = index; |
| 1258 | |
| 1259 | return skb->len; |
| 1260 | } |
| 1261 | |
Eric W. Biederman | 8de147d | 2015-03-03 19:14:31 -0600 | [diff] [blame] | 1262 | static inline size_t lfib_nlmsg_size(struct mpls_route *rt) |
| 1263 | { |
| 1264 | size_t payload = |
| 1265 | NLMSG_ALIGN(sizeof(struct rtmsg)) |
Eric W. Biederman | 8de147d | 2015-03-03 19:14:31 -0600 | [diff] [blame] | 1266 | + nla_total_size(4); /* RTA_DST */ |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1267 | |
| 1268 | if (rt->rt_nhn == 1) { |
| 1269 | struct mpls_nh *nh = rt->rt_nh; |
| 1270 | |
| 1271 | if (nh->nh_dev) |
| 1272 | payload += nla_total_size(4); /* RTA_OIF */ |
| 1273 | payload += nla_total_size(2 + nh->nh_via_alen); /* RTA_VIA */ |
| 1274 | if (nh->nh_labels) /* RTA_NEWDST */ |
| 1275 | payload += nla_total_size(nh->nh_labels * 4); |
| 1276 | } else { |
| 1277 | /* each nexthop is packed in an attribute */ |
| 1278 | size_t nhsize = 0; |
| 1279 | |
| 1280 | for_nexthops(rt) { |
| 1281 | nhsize += nla_total_size(sizeof(struct rtnexthop)); |
| 1282 | nhsize += nla_total_size(2 + nh->nh_via_alen); |
| 1283 | if (nh->nh_labels) |
| 1284 | nhsize += nla_total_size(nh->nh_labels * 4); |
| 1285 | } endfor_nexthops(rt); |
| 1286 | /* nested attribute */ |
| 1287 | payload += nla_total_size(nhsize); |
| 1288 | } |
| 1289 | |
Eric W. Biederman | 8de147d | 2015-03-03 19:14:31 -0600 | [diff] [blame] | 1290 | return payload; |
| 1291 | } |
| 1292 | |
| 1293 | static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt, |
| 1294 | struct nlmsghdr *nlh, struct net *net, u32 portid, |
| 1295 | unsigned int nlm_flags) |
| 1296 | { |
| 1297 | struct sk_buff *skb; |
| 1298 | u32 seq = nlh ? nlh->nlmsg_seq : 0; |
| 1299 | int err = -ENOBUFS; |
| 1300 | |
| 1301 | skb = nlmsg_new(lfib_nlmsg_size(rt), GFP_KERNEL); |
| 1302 | if (skb == NULL) |
| 1303 | goto errout; |
| 1304 | |
| 1305 | err = mpls_dump_route(skb, portid, seq, event, label, rt, nlm_flags); |
| 1306 | if (err < 0) { |
| 1307 | /* -EMSGSIZE implies BUG in lfib_nlmsg_size */ |
| 1308 | WARN_ON(err == -EMSGSIZE); |
| 1309 | kfree_skb(skb); |
| 1310 | goto errout; |
| 1311 | } |
| 1312 | rtnl_notify(skb, net, portid, RTNLGRP_MPLS_ROUTE, nlh, GFP_KERNEL); |
| 1313 | |
| 1314 | return; |
| 1315 | errout: |
| 1316 | if (err < 0) |
| 1317 | rtnl_set_sk_err(net, RTNLGRP_MPLS_ROUTE, err); |
| 1318 | } |
| 1319 | |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1320 | static int resize_platform_label_table(struct net *net, size_t limit) |
| 1321 | { |
| 1322 | size_t size = sizeof(struct mpls_route *) * limit; |
| 1323 | size_t old_limit; |
| 1324 | size_t cp_size; |
| 1325 | struct mpls_route __rcu **labels = NULL, **old; |
| 1326 | struct mpls_route *rt0 = NULL, *rt2 = NULL; |
| 1327 | unsigned index; |
| 1328 | |
| 1329 | if (size) { |
| 1330 | labels = kzalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); |
| 1331 | if (!labels) |
| 1332 | labels = vzalloc(size); |
| 1333 | |
| 1334 | if (!labels) |
| 1335 | goto nolabels; |
| 1336 | } |
| 1337 | |
| 1338 | /* In case the predefined labels need to be populated */ |
Tom Herbert | 78f5b89 | 2015-05-07 08:08:51 -0700 | [diff] [blame] | 1339 | if (limit > MPLS_LABEL_IPV4NULL) { |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1340 | struct net_device *lo = net->loopback_dev; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1341 | rt0 = mpls_rt_alloc(1); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1342 | if (!rt0) |
| 1343 | goto nort0; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1344 | RCU_INIT_POINTER(rt0->rt_nh->nh_dev, lo); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1345 | rt0->rt_protocol = RTPROT_KERNEL; |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 1346 | rt0->rt_payload_type = MPT_IPV4; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1347 | rt0->rt_nh->nh_via_table = NEIGH_LINK_TABLE; |
| 1348 | memcpy(rt0->rt_nh->nh_via, lo->dev_addr, lo->addr_len); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1349 | } |
Tom Herbert | 78f5b89 | 2015-05-07 08:08:51 -0700 | [diff] [blame] | 1350 | if (limit > MPLS_LABEL_IPV6NULL) { |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1351 | struct net_device *lo = net->loopback_dev; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1352 | rt2 = mpls_rt_alloc(1); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1353 | if (!rt2) |
| 1354 | goto nort2; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1355 | RCU_INIT_POINTER(rt2->rt_nh->nh_dev, lo); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1356 | rt2->rt_protocol = RTPROT_KERNEL; |
Robert Shearman | 118d523 | 2015-08-06 11:04:56 +0100 | [diff] [blame] | 1357 | rt2->rt_payload_type = MPT_IPV6; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1358 | rt2->rt_nh->nh_via_table = NEIGH_LINK_TABLE; |
| 1359 | memcpy(rt2->rt_nh->nh_via, lo->dev_addr, lo->addr_len); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | rtnl_lock(); |
| 1363 | /* Remember the original table */ |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1364 | old = rtnl_dereference(net->mpls.platform_label); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1365 | old_limit = net->mpls.platform_labels; |
| 1366 | |
| 1367 | /* Free any labels beyond the new table */ |
| 1368 | for (index = limit; index < old_limit; index++) |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 1369 | mpls_route_update(net, index, NULL, NULL); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1370 | |
| 1371 | /* Copy over the old labels */ |
| 1372 | cp_size = size; |
| 1373 | if (old_limit < limit) |
| 1374 | cp_size = old_limit * sizeof(struct mpls_route *); |
| 1375 | |
| 1376 | memcpy(labels, old, cp_size); |
| 1377 | |
| 1378 | /* If needed set the predefined labels */ |
Tom Herbert | 78f5b89 | 2015-05-07 08:08:51 -0700 | [diff] [blame] | 1379 | if ((old_limit <= MPLS_LABEL_IPV6NULL) && |
| 1380 | (limit > MPLS_LABEL_IPV6NULL)) { |
| 1381 | RCU_INIT_POINTER(labels[MPLS_LABEL_IPV6NULL], rt2); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1382 | rt2 = NULL; |
| 1383 | } |
| 1384 | |
Tom Herbert | 78f5b89 | 2015-05-07 08:08:51 -0700 | [diff] [blame] | 1385 | if ((old_limit <= MPLS_LABEL_IPV4NULL) && |
| 1386 | (limit > MPLS_LABEL_IPV4NULL)) { |
| 1387 | RCU_INIT_POINTER(labels[MPLS_LABEL_IPV4NULL], rt0); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1388 | rt0 = NULL; |
| 1389 | } |
| 1390 | |
| 1391 | /* Update the global pointers */ |
| 1392 | net->mpls.platform_labels = limit; |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1393 | rcu_assign_pointer(net->mpls.platform_label, labels); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1394 | |
| 1395 | rtnl_unlock(); |
| 1396 | |
| 1397 | mpls_rt_free(rt2); |
| 1398 | mpls_rt_free(rt0); |
| 1399 | |
| 1400 | if (old) { |
| 1401 | synchronize_rcu(); |
| 1402 | kvfree(old); |
| 1403 | } |
| 1404 | return 0; |
| 1405 | |
| 1406 | nort2: |
| 1407 | mpls_rt_free(rt0); |
| 1408 | nort0: |
| 1409 | kvfree(labels); |
| 1410 | nolabels: |
| 1411 | return -ENOMEM; |
| 1412 | } |
| 1413 | |
| 1414 | static int mpls_platform_labels(struct ctl_table *table, int write, |
| 1415 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 1416 | { |
| 1417 | struct net *net = table->data; |
| 1418 | int platform_labels = net->mpls.platform_labels; |
| 1419 | int ret; |
| 1420 | struct ctl_table tmp = { |
| 1421 | .procname = table->procname, |
| 1422 | .data = &platform_labels, |
| 1423 | .maxlen = sizeof(int), |
| 1424 | .mode = table->mode, |
| 1425 | .extra1 = &zero, |
| 1426 | .extra2 = &label_limit, |
| 1427 | }; |
| 1428 | |
| 1429 | ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); |
| 1430 | |
| 1431 | if (write && ret == 0) |
| 1432 | ret = resize_platform_label_table(net, platform_labels); |
| 1433 | |
| 1434 | return ret; |
| 1435 | } |
| 1436 | |
Robert Shearman | 37bde79 | 2015-04-22 11:14:38 +0100 | [diff] [blame] | 1437 | static const struct ctl_table mpls_table[] = { |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1438 | { |
| 1439 | .procname = "platform_labels", |
| 1440 | .data = NULL, |
| 1441 | .maxlen = sizeof(int), |
| 1442 | .mode = 0644, |
| 1443 | .proc_handler = mpls_platform_labels, |
| 1444 | }, |
| 1445 | { } |
| 1446 | }; |
| 1447 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1448 | static int mpls_net_init(struct net *net) |
| 1449 | { |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1450 | struct ctl_table *table; |
| 1451 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1452 | net->mpls.platform_labels = 0; |
| 1453 | net->mpls.platform_label = NULL; |
| 1454 | |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1455 | table = kmemdup(mpls_table, sizeof(mpls_table), GFP_KERNEL); |
| 1456 | if (table == NULL) |
| 1457 | return -ENOMEM; |
| 1458 | |
| 1459 | table[0].data = net; |
| 1460 | net->mpls.ctl = register_net_sysctl(net, "net/mpls", table); |
Nikolay Aleksandrov | 6ea3c9d5 | 2015-08-31 10:44:19 -0700 | [diff] [blame] | 1461 | if (net->mpls.ctl == NULL) { |
| 1462 | kfree(table); |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1463 | return -ENOMEM; |
Nikolay Aleksandrov | 6ea3c9d5 | 2015-08-31 10:44:19 -0700 | [diff] [blame] | 1464 | } |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1465 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1466 | return 0; |
| 1467 | } |
| 1468 | |
| 1469 | static void mpls_net_exit(struct net *net) |
| 1470 | { |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1471 | struct mpls_route __rcu **platform_label; |
| 1472 | size_t platform_labels; |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1473 | struct ctl_table *table; |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1474 | unsigned int index; |
| 1475 | |
Eric W. Biederman | 7720c01 | 2015-03-03 19:11:20 -0600 | [diff] [blame] | 1476 | table = net->mpls.ctl->ctl_table_arg; |
| 1477 | unregister_net_sysctl_table(net->mpls.ctl); |
| 1478 | kfree(table); |
| 1479 | |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1480 | /* An rcu grace period has passed since there was a device in |
| 1481 | * the network namespace (and thus the last in flight packet) |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1482 | * left this network namespace. This is because |
| 1483 | * unregister_netdevice_many and netdev_run_todo has completed |
| 1484 | * for each network device that was in this network namespace. |
| 1485 | * |
| 1486 | * As such no additional rcu synchronization is necessary when |
| 1487 | * freeing the platform_label table. |
| 1488 | */ |
| 1489 | rtnl_lock(); |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1490 | platform_label = rtnl_dereference(net->mpls.platform_label); |
| 1491 | platform_labels = net->mpls.platform_labels; |
| 1492 | for (index = 0; index < platform_labels; index++) { |
| 1493 | struct mpls_route *rt = rtnl_dereference(platform_label[index]); |
| 1494 | RCU_INIT_POINTER(platform_label[index], NULL); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1495 | mpls_rt_free(rt); |
| 1496 | } |
| 1497 | rtnl_unlock(); |
| 1498 | |
Eric W. Biederman | 19d0c34 | 2015-03-07 16:21:56 -0600 | [diff] [blame] | 1499 | kvfree(platform_label); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | static struct pernet_operations mpls_net_ops = { |
| 1503 | .init = mpls_net_init, |
| 1504 | .exit = mpls_net_exit, |
| 1505 | }; |
| 1506 | |
| 1507 | static int __init mpls_init(void) |
| 1508 | { |
| 1509 | int err; |
| 1510 | |
| 1511 | BUILD_BUG_ON(sizeof(struct mpls_shim_hdr) != 4); |
| 1512 | |
| 1513 | err = register_pernet_subsys(&mpls_net_ops); |
| 1514 | if (err) |
| 1515 | goto out; |
| 1516 | |
| 1517 | err = register_netdevice_notifier(&mpls_dev_notifier); |
| 1518 | if (err) |
| 1519 | goto out_unregister_pernet; |
| 1520 | |
| 1521 | dev_add_pack(&mpls_packet_type); |
| 1522 | |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1523 | rtnl_register(PF_MPLS, RTM_NEWROUTE, mpls_rtm_newroute, NULL, NULL); |
| 1524 | rtnl_register(PF_MPLS, RTM_DELROUTE, mpls_rtm_delroute, NULL, NULL); |
| 1525 | rtnl_register(PF_MPLS, RTM_GETROUTE, NULL, mpls_dump_routes, NULL); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1526 | err = 0; |
| 1527 | out: |
| 1528 | return err; |
| 1529 | |
| 1530 | out_unregister_pernet: |
| 1531 | unregister_pernet_subsys(&mpls_net_ops); |
| 1532 | goto out; |
| 1533 | } |
| 1534 | module_init(mpls_init); |
| 1535 | |
| 1536 | static void __exit mpls_exit(void) |
| 1537 | { |
Eric W. Biederman | 03c0566 | 2015-03-03 19:13:56 -0600 | [diff] [blame] | 1538 | rtnl_unregister_all(PF_MPLS); |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1539 | dev_remove_pack(&mpls_packet_type); |
| 1540 | unregister_netdevice_notifier(&mpls_dev_notifier); |
| 1541 | unregister_pernet_subsys(&mpls_net_ops); |
| 1542 | } |
| 1543 | module_exit(mpls_exit); |
| 1544 | |
| 1545 | MODULE_DESCRIPTION("MultiProtocol Label Switching"); |
| 1546 | MODULE_LICENSE("GPL v2"); |
| 1547 | MODULE_ALIAS_NETPROTO(PF_MPLS); |