ar71xx: keep the RouterBOARD Power LED in On state
[oweals/openwrt.git] / target / linux / generic / patches-4.9 / 666-Add-support-for-MAP-E-FMRs-mesh-mode.patch
1 From 775d6fe74d1eaec2ba387535b068dde2dc89de9e Mon Sep 17 00:00:00 2001
2 From: Steven Barth <steven@midlink.org>
3 Date: Thu, 22 May 2014 09:49:05 +0200
4 Subject: [PATCH] Add support for MAP-E FMRs (mesh mode)
5
6 MAP-E FMRs (draft-ietf-softwire-map-10) are rules for IPv4-communication
7 between MAP CEs (mesh mode) without the need to forward such data to a
8 border relay. This is similar to how 6rd works but for IPv4 over IPv6.
9
10 Signed-off-by: Steven Barth <cyrus@openwrt.org>
11 ---
12  include/net/ip6_tunnel.h       |  13 ++
13  include/uapi/linux/if_tunnel.h |  13 ++
14  net/ipv6/ip6_tunnel.c          | 276 +++++++++++++++++++++++++++++++++++++++--
15  3 files changed, 291 insertions(+), 11 deletions(-)
16
17 --- a/include/net/ip6_tunnel.h
18 +++ b/include/net/ip6_tunnel.h
19 @@ -17,6 +17,18 @@
20  /* determine capability on a per-packet basis */
21  #define IP6_TNL_F_CAP_PER_PACKET 0x40000
22  
23 +/* IPv6 tunnel FMR */
24 +struct __ip6_tnl_fmr {
25 +       struct __ip6_tnl_fmr *next; /* next fmr in list */
26 +       struct in6_addr ip6_prefix;
27 +       struct in_addr ip4_prefix;
28 +
29 +       __u8 ip6_prefix_len;
30 +       __u8 ip4_prefix_len;
31 +       __u8 ea_len;
32 +       __u8 offset;
33 +};
34 +
35  struct __ip6_tnl_parm {
36         char name[IFNAMSIZ];    /* name of tunnel device */
37         int link;               /* ifindex of underlying L2 interface */
38 @@ -28,6 +40,7 @@ struct __ip6_tnl_parm {
39         __u32 flags;            /* tunnel flags */
40         struct in6_addr laddr;  /* local tunnel end-point address */
41         struct in6_addr raddr;  /* remote tunnel end-point address */
42 +       struct __ip6_tnl_fmr *fmrs;     /* FMRs */
43  
44         __be16                  i_flags;
45         __be16                  o_flags;
46 --- a/include/uapi/linux/if_tunnel.h
47 +++ b/include/uapi/linux/if_tunnel.h
48 @@ -75,10 +75,23 @@ enum {
49         IFLA_IPTUN_ENCAP_SPORT,
50         IFLA_IPTUN_ENCAP_DPORT,
51         IFLA_IPTUN_COLLECT_METADATA,
52 +       IFLA_IPTUN_FMRS,
53         __IFLA_IPTUN_MAX,
54  };
55  #define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1)
56  
57 +enum {
58 +       IFLA_IPTUN_FMR_UNSPEC,
59 +       IFLA_IPTUN_FMR_IP6_PREFIX,
60 +       IFLA_IPTUN_FMR_IP4_PREFIX,
61 +       IFLA_IPTUN_FMR_IP6_PREFIX_LEN,
62 +       IFLA_IPTUN_FMR_IP4_PREFIX_LEN,
63 +       IFLA_IPTUN_FMR_EA_LEN,
64 +       IFLA_IPTUN_FMR_OFFSET,
65 +       __IFLA_IPTUN_FMR_MAX,
66 +};
67 +#define IFLA_IPTUN_FMR_MAX (__IFLA_IPTUN_FMR_MAX - 1)
68 +
69  enum tunnel_encap_types {
70         TUNNEL_ENCAP_NONE,
71         TUNNEL_ENCAP_FOU,
72 --- a/net/ipv6/ip6_tunnel.c
73 +++ b/net/ipv6/ip6_tunnel.c
74 @@ -16,6 +16,8 @@
75   *      as published by the Free Software Foundation; either version
76   *      2 of the License, or (at your option) any later version.
77   *
78 + *     Changes:
79 + * Steven Barth <cyrus@openwrt.org>:           MAP-E FMR support
80   */
81  
82  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
83 @@ -72,9 +74,9 @@ static bool log_ecn_error = true;
84  module_param(log_ecn_error, bool, 0644);
85  MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86  
87 -static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
88 +static u32 HASH(const struct in6_addr *addr)
89  {
90 -       u32 hash = ipv6_addr_hash(addr1) ^ ipv6_addr_hash(addr2);
91 +       u32 hash = ipv6_addr_hash(addr);
92  
93         return hash_32(hash, IP6_TUNNEL_HASH_SIZE_SHIFT);
94  }
95 @@ -141,20 +143,29 @@ static struct net_device_stats *ip6_get_
96  static struct ip6_tnl *
97  ip6_tnl_lookup(struct net *net, const struct in6_addr *remote, const struct in6_addr *local)
98  {
99 -       unsigned int hash = HASH(remote, local);
100 +       unsigned int hash = HASH(local);
101         struct ip6_tnl *t;
102         struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
103         struct in6_addr any;
104 +       struct __ip6_tnl_fmr *fmr;
105  
106         for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
107 -               if (ipv6_addr_equal(local, &t->parms.laddr) &&
108 -                   ipv6_addr_equal(remote, &t->parms.raddr) &&
109 -                   (t->dev->flags & IFF_UP))
110 +               if (!ipv6_addr_equal(local, &t->parms.laddr) ||
111 +                               !(t->dev->flags & IFF_UP))
112 +                       continue;
113 +
114 +               if (ipv6_addr_equal(remote, &t->parms.raddr))
115                         return t;
116 +
117 +               for (fmr = t->parms.fmrs; fmr; fmr = fmr->next) {
118 +                       if (ipv6_prefix_equal(remote, &fmr->ip6_prefix,
119 +                                       fmr->ip6_prefix_len))
120 +                               return t;
121 +               }
122         }
123  
124         memset(&any, 0, sizeof(any));
125 -       hash = HASH(&any, local);
126 +       hash = HASH(local);
127         for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
128                 if (ipv6_addr_equal(local, &t->parms.laddr) &&
129                     ipv6_addr_any(&t->parms.raddr) &&
130 @@ -162,7 +173,7 @@ ip6_tnl_lookup(struct net *net, const st
131                         return t;
132         }
133  
134 -       hash = HASH(remote, &any);
135 +       hash = HASH(&any);
136         for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
137                 if (ipv6_addr_equal(remote, &t->parms.raddr) &&
138                     ipv6_addr_any(&t->parms.laddr) &&
139 @@ -202,7 +213,7 @@ ip6_tnl_bucket(struct ip6_tnl_net *ip6n,
140  
141         if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
142                 prio = 1;
143 -               h = HASH(remote, local);
144 +               h = HASH(local);
145         }
146         return &ip6n->tnls[prio][h];
147  }
148 @@ -381,6 +392,12 @@ ip6_tnl_dev_uninit(struct net_device *de
149         struct net *net = t->net;
150         struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
151  
152 +       while (t->parms.fmrs) {
153 +               struct __ip6_tnl_fmr *next = t->parms.fmrs->next;
154 +               kfree(t->parms.fmrs);
155 +               t->parms.fmrs = next;
156 +       }
157 +
158         if (dev == ip6n->fb_tnl_dev)
159                 RCU_INIT_POINTER(ip6n->tnls_wc[0], NULL);
160         else
161 @@ -777,6 +794,107 @@ int ip6_tnl_rcv_ctl(struct ip6_tnl *t,
162  }
163  EXPORT_SYMBOL_GPL(ip6_tnl_rcv_ctl);
164  
165 +/**
166 + * ip4ip6_fmr_calc - calculate target / source IPv6-address based on FMR
167 + *   @dest: destination IPv6 address buffer
168 + *   @skb: received socket buffer
169 + *   @fmr: MAP FMR
170 + *   @xmit: Calculate for xmit or rcv
171 + **/
172 +static void ip4ip6_fmr_calc(struct in6_addr *dest,
173 +               const struct iphdr *iph, const uint8_t *end,
174 +               const struct __ip6_tnl_fmr *fmr, bool xmit)
175 +{
176 +       int psidlen = fmr->ea_len - (32 - fmr->ip4_prefix_len);
177 +       u8 *portp = NULL;
178 +       bool use_dest_addr;
179 +       const struct iphdr *dsth = iph;
180 +
181 +       if ((u8*)dsth >= end)
182 +               return;
183 +
184 +       /* find significant IP header */
185 +       if (iph->protocol == IPPROTO_ICMP) {
186 +               struct icmphdr *ih = (struct icmphdr*)(((u8*)dsth) + dsth->ihl * 4);
187 +               if (ih && ((u8*)&ih[1]) <= end && (
188 +                       ih->type == ICMP_DEST_UNREACH ||
189 +                       ih->type == ICMP_SOURCE_QUENCH ||
190 +                       ih->type == ICMP_TIME_EXCEEDED ||
191 +                       ih->type == ICMP_PARAMETERPROB ||
192 +                       ih->type == ICMP_REDIRECT))
193 +                               dsth = (const struct iphdr*)&ih[1];
194 +       }
195 +
196 +       /* in xmit-path use dest port by default and source port only if
197 +               this is an ICMP reply to something else; vice versa in rcv-path */
198 +       use_dest_addr = (xmit && dsth == iph) || (!xmit && dsth != iph);
199 +
200 +       /* get dst port */
201 +       if (((u8*)&dsth[1]) <= end && (
202 +               dsth->protocol == IPPROTO_UDP ||
203 +               dsth->protocol == IPPROTO_TCP ||
204 +               dsth->protocol == IPPROTO_SCTP ||
205 +               dsth->protocol == IPPROTO_DCCP)) {
206 +                       /* for UDP, TCP, SCTP and DCCP source and dest port
207 +                       follow IPv4 header directly */
208 +                       portp = ((u8*)dsth) + dsth->ihl * 4;
209 +
210 +                       if (use_dest_addr)
211 +                               portp += sizeof(u16);
212 +       } else if (iph->protocol == IPPROTO_ICMP) {
213 +               struct icmphdr *ih = (struct icmphdr*)(((u8*)dsth) + dsth->ihl * 4);
214 +
215 +               /* use icmp identifier as port */
216 +               if (((u8*)&ih) <= end && (
217 +                   (use_dest_addr && (
218 +                   ih->type == ICMP_ECHOREPLY ||
219 +                       ih->type == ICMP_TIMESTAMPREPLY ||
220 +                       ih->type == ICMP_INFO_REPLY ||
221 +                       ih->type == ICMP_ADDRESSREPLY)) ||
222 +                       (!use_dest_addr && (
223 +                       ih->type == ICMP_ECHO ||
224 +                       ih->type == ICMP_TIMESTAMP ||
225 +                       ih->type == ICMP_INFO_REQUEST ||
226 +                       ih->type == ICMP_ADDRESS)
227 +                       )))
228 +                               portp = (u8*)&ih->un.echo.id;
229 +       }
230 +
231 +       if ((portp && &portp[2] <= end) || psidlen == 0) {
232 +               int frombyte = fmr->ip6_prefix_len / 8;
233 +               int fromrem = fmr->ip6_prefix_len % 8;
234 +               int bytes = sizeof(struct in6_addr) - frombyte;
235 +               const u32 *addr = (use_dest_addr) ? &iph->daddr : &iph->saddr;
236 +               u64 eabits = ((u64)ntohl(*addr)) << (32 + fmr->ip4_prefix_len);
237 +               u64 t = 0;
238 +
239 +               /* extract PSID from port and add it to eabits */
240 +               u16 psidbits = 0;
241 +               if (psidlen > 0) {
242 +                       psidbits = ((u16)portp[0]) << 8 | ((u16)portp[1]);
243 +                       psidbits >>= 16 - psidlen - fmr->offset;
244 +                       psidbits = (u16)(psidbits << (16 - psidlen));
245 +                       eabits |= ((u64)psidbits) << (48 - (fmr->ea_len - psidlen));
246 +               }
247 +
248 +               /* rewrite destination address */
249 +               *dest = fmr->ip6_prefix;
250 +               memcpy(&dest->s6_addr[10], addr, sizeof(*addr));
251 +               dest->s6_addr16[7] = htons(psidbits >> (16 - psidlen));
252 +
253 +               if (bytes > sizeof(u64))
254 +                       bytes = sizeof(u64);
255 +
256 +               /* insert eabits */
257 +               memcpy(&t, &dest->s6_addr[frombyte], bytes);
258 +               t = be64_to_cpu(t) & ~(((((u64)1) << fmr->ea_len) - 1)
259 +                       << (64 - fmr->ea_len - fromrem));
260 +               t = cpu_to_be64(t | (eabits >> fromrem));
261 +               memcpy(&dest->s6_addr[frombyte], &t, bytes);
262 +       }
263 +}
264 +
265 +
266  static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
267                          const struct tnl_ptk_info *tpi,
268                          struct metadata_dst *tun_dst,
269 @@ -829,6 +947,27 @@ static int __ip6_tnl_rcv(struct ip6_tnl
270         skb_reset_network_header(skb);
271         memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
272  
273 +       if (tpi->proto == htons(ETH_P_IP) &&
274 +               !ipv6_addr_equal(&ipv6h->saddr, &tunnel->parms.raddr)) {
275 +                       /* Packet didn't come from BR, so lookup FMR */
276 +                       struct __ip6_tnl_fmr *fmr;
277 +                       struct in6_addr expected = tunnel->parms.raddr;
278 +                       for (fmr = tunnel->parms.fmrs; fmr; fmr = fmr->next)
279 +                               if (ipv6_prefix_equal(&ipv6h->saddr,
280 +                                       &fmr->ip6_prefix, fmr->ip6_prefix_len))
281 +                                               break;
282 +
283 +                       /* Check that IPv6 matches IPv4 source to prevent spoofing */
284 +                       if (fmr)
285 +                               ip4ip6_fmr_calc(&expected, ip_hdr(skb),
286 +                                               skb_tail_pointer(skb), fmr, false);
287 +
288 +                       if (!ipv6_addr_equal(&ipv6h->saddr, &expected)) {
289 +                               rcu_read_unlock();
290 +                               goto drop;
291 +                       }
292 +       }
293 +
294         __skb_tunnel_rx(skb, tunnel->dev, tunnel->net);
295  
296         err = dscp_ecn_decapsulate(tunnel, ipv6h, skb);
297 @@ -958,6 +1097,7 @@ static void init_tel_txopt(struct ipv6_t
298         opt->ops.opt_nflen = 8;
299  }
300  
301 +
302  /**
303   * ip6_tnl_addr_conflict - compare packet addresses to tunnel's own
304   *   @t: the outgoing tunnel device
305 @@ -1285,6 +1425,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
306  {
307         struct ip6_tnl *t = netdev_priv(dev);
308         struct ipv6hdr *ipv6h = ipv6_hdr(skb);
309 +       struct __ip6_tnl_fmr *fmr;
310         int encap_limit = -1;
311         __u16 offset;
312         struct flowi6 fl6;
313 @@ -1343,6 +1484,18 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
314                         fl6.flowi6_mark = skb->mark;
315         }
316  
317 +       /* try to find matching FMR */
318 +       for (fmr = t->parms.fmrs; fmr; fmr = fmr->next) {
319 +               unsigned mshift = 32 - fmr->ip4_prefix_len;
320 +               if (ntohl(fmr->ip4_prefix.s_addr) >> mshift ==
321 +                               ntohl(ip_hdr(skb)->daddr) >> mshift)
322 +                       break;
323 +       }
324 +
325 +       /* change dstaddr according to FMR */
326 +       if (fmr)
327 +               ip4ip6_fmr_calc(&fl6.daddr, ip_hdr(skb), skb_tail_pointer(skb), fmr, true);
328 +
329         if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))
330                 return -1;
331  
332 @@ -1470,6 +1623,14 @@ ip6_tnl_change(struct ip6_tnl *t, const
333         t->parms.flowinfo = p->flowinfo;
334         t->parms.link = p->link;
335         t->parms.proto = p->proto;
336 +
337 +       while (t->parms.fmrs) {
338 +               struct __ip6_tnl_fmr *next = t->parms.fmrs->next;
339 +               kfree(t->parms.fmrs);
340 +               t->parms.fmrs = next;
341 +       }
342 +       t->parms.fmrs = p->fmrs;
343 +
344         dst_cache_reset(&t->dst_cache);
345         ip6_tnl_link_config(t);
346         return 0;
347 @@ -1508,6 +1669,7 @@ ip6_tnl_parm_from_user(struct __ip6_tnl_
348         p->flowinfo = u->flowinfo;
349         p->link = u->link;
350         p->proto = u->proto;
351 +       p->fmrs = NULL;
352         memcpy(p->name, u->name, sizeof(u->name));
353  }
354  
355 @@ -1885,6 +2047,15 @@ static int ip6_tnl_validate(struct nlatt
356         return 0;
357  }
358  
359 +static const struct nla_policy ip6_tnl_fmr_policy[IFLA_IPTUN_FMR_MAX + 1] = {
360 +       [IFLA_IPTUN_FMR_IP6_PREFIX] = { .len = sizeof(struct in6_addr) },
361 +       [IFLA_IPTUN_FMR_IP4_PREFIX] = { .len = sizeof(struct in_addr) },
362 +       [IFLA_IPTUN_FMR_IP6_PREFIX_LEN] = { .type = NLA_U8 },
363 +       [IFLA_IPTUN_FMR_IP4_PREFIX_LEN] = { .type = NLA_U8 },
364 +       [IFLA_IPTUN_FMR_EA_LEN] = { .type = NLA_U8 },
365 +       [IFLA_IPTUN_FMR_OFFSET] = { .type = NLA_U8 }
366 +};
367 +
368  static void ip6_tnl_netlink_parms(struct nlattr *data[],
369                                   struct __ip6_tnl_parm *parms)
370  {
371 @@ -1919,6 +2090,46 @@ static void ip6_tnl_netlink_parms(struct
372  
373         if (data[IFLA_IPTUN_COLLECT_METADATA])
374                 parms->collect_md = true;
375 +
376 +       if (data[IFLA_IPTUN_FMRS]) {
377 +               unsigned rem;
378 +               struct nlattr *fmr;
379 +               nla_for_each_nested(fmr, data[IFLA_IPTUN_FMRS], rem) {
380 +                       struct nlattr *fmrd[IFLA_IPTUN_FMR_MAX + 1], *c;
381 +                       struct __ip6_tnl_fmr *nfmr;
382 +
383 +                       nla_parse_nested(fmrd, IFLA_IPTUN_FMR_MAX,
384 +                               fmr, ip6_tnl_fmr_policy);
385 +
386 +                       if (!(nfmr = kzalloc(sizeof(*nfmr), GFP_KERNEL)))
387 +                               continue;
388 +
389 +                       nfmr->offset = 6;
390 +
391 +                       if ((c = fmrd[IFLA_IPTUN_FMR_IP6_PREFIX]))
392 +                               nla_memcpy(&nfmr->ip6_prefix, fmrd[IFLA_IPTUN_FMR_IP6_PREFIX],
393 +                                       sizeof(nfmr->ip6_prefix));
394 +
395 +                       if ((c = fmrd[IFLA_IPTUN_FMR_IP4_PREFIX]))
396 +                               nla_memcpy(&nfmr->ip4_prefix, fmrd[IFLA_IPTUN_FMR_IP4_PREFIX],
397 +                                       sizeof(nfmr->ip4_prefix));
398 +
399 +                       if ((c = fmrd[IFLA_IPTUN_FMR_IP6_PREFIX_LEN]))
400 +                               nfmr->ip6_prefix_len = nla_get_u8(c);
401 +
402 +                       if ((c = fmrd[IFLA_IPTUN_FMR_IP4_PREFIX_LEN]))
403 +                               nfmr->ip4_prefix_len = nla_get_u8(c);
404 +
405 +                       if ((c = fmrd[IFLA_IPTUN_FMR_EA_LEN]))
406 +                               nfmr->ea_len = nla_get_u8(c);
407 +
408 +                       if ((c = fmrd[IFLA_IPTUN_FMR_OFFSET]))
409 +                               nfmr->offset = nla_get_u8(c);
410 +
411 +                       nfmr->next = parms->fmrs;
412 +                       parms->fmrs = nfmr;
413 +               }
414 +       }
415  }
416  
417  static bool ip6_tnl_netlink_encap_parms(struct nlattr *data[],
418 @@ -2028,6 +2239,12 @@ static void ip6_tnl_dellink(struct net_d
419  
420  static size_t ip6_tnl_get_size(const struct net_device *dev)
421  {
422 +       const struct ip6_tnl *t = netdev_priv(dev);
423 +       struct __ip6_tnl_fmr *c;
424 +       int fmrs = 0;
425 +       for (c = t->parms.fmrs; c; c = c->next)
426 +               ++fmrs;
427 +
428         return
429                 /* IFLA_IPTUN_LINK */
430                 nla_total_size(4) +
431 @@ -2055,6 +2272,24 @@ static size_t ip6_tnl_get_size(const str
432                 nla_total_size(2) +
433                 /* IFLA_IPTUN_COLLECT_METADATA */
434                 nla_total_size(0) +
435 +               /* IFLA_IPTUN_FMRS */
436 +               nla_total_size(0) +
437 +               (
438 +                       /* nest */
439 +                       nla_total_size(0) +
440 +                       /* IFLA_IPTUN_FMR_IP6_PREFIX */
441 +                       nla_total_size(sizeof(struct in6_addr)) +
442 +                       /* IFLA_IPTUN_FMR_IP4_PREFIX */
443 +                       nla_total_size(sizeof(struct in_addr)) +
444 +                       /* IFLA_IPTUN_FMR_EA_LEN */
445 +                       nla_total_size(1) +
446 +                       /* IFLA_IPTUN_FMR_IP6_PREFIX_LEN */
447 +                       nla_total_size(1) +
448 +                       /* IFLA_IPTUN_FMR_IP4_PREFIX_LEN */
449 +                       nla_total_size(1) +
450 +                       /* IFLA_IPTUN_FMR_OFFSET */
451 +                       nla_total_size(1)
452 +               ) * fmrs +
453                 0;
454  }
455  
456 @@ -2062,6 +2297,9 @@ static int ip6_tnl_fill_info(struct sk_b
457  {
458         struct ip6_tnl *tunnel = netdev_priv(dev);
459         struct __ip6_tnl_parm *parm = &tunnel->parms;
460 +       struct __ip6_tnl_fmr *c;
461 +       int fmrcnt = 0;
462 +       struct nlattr *fmrs;
463  
464         if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
465             nla_put_in6_addr(skb, IFLA_IPTUN_LOCAL, &parm->laddr) ||
466 @@ -2070,9 +2308,27 @@ static int ip6_tnl_fill_info(struct sk_b
467             nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) ||
468             nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) ||
469             nla_put_u32(skb, IFLA_IPTUN_FLAGS, parm->flags) ||
470 -           nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->proto))
471 +           nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->proto) ||
472 +           !(fmrs = nla_nest_start(skb, IFLA_IPTUN_FMRS)))
473                 goto nla_put_failure;
474  
475 +       for (c = parm->fmrs; c; c = c->next) {
476 +               struct nlattr *fmr = nla_nest_start(skb, ++fmrcnt);
477 +               if (!fmr ||
478 +                       nla_put(skb, IFLA_IPTUN_FMR_IP6_PREFIX,
479 +                               sizeof(c->ip6_prefix), &c->ip6_prefix) ||
480 +                       nla_put(skb, IFLA_IPTUN_FMR_IP4_PREFIX,
481 +                               sizeof(c->ip4_prefix), &c->ip4_prefix) ||
482 +                       nla_put_u8(skb, IFLA_IPTUN_FMR_IP6_PREFIX_LEN, c->ip6_prefix_len) ||
483 +                       nla_put_u8(skb, IFLA_IPTUN_FMR_IP4_PREFIX_LEN, c->ip4_prefix_len) ||
484 +                       nla_put_u8(skb, IFLA_IPTUN_FMR_EA_LEN, c->ea_len) ||
485 +                       nla_put_u8(skb, IFLA_IPTUN_FMR_OFFSET, c->offset))
486 +                               goto nla_put_failure;
487 +
488 +               nla_nest_end(skb, fmr);
489 +       }
490 +       nla_nest_end(skb, fmrs);
491 +
492         if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE, tunnel->encap.type) ||
493             nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT, tunnel->encap.sport) ||
494             nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT, tunnel->encap.dport) ||
495 @@ -2110,6 +2366,7 @@ static const struct nla_policy ip6_tnl_p
496         [IFLA_IPTUN_ENCAP_SPORT]        = { .type = NLA_U16 },
497         [IFLA_IPTUN_ENCAP_DPORT]        = { .type = NLA_U16 },
498         [IFLA_IPTUN_COLLECT_METADATA]   = { .type = NLA_FLAG },
499 +       [IFLA_IPTUN_FMRS]               = { .type = NLA_NESTED },
500  };
501  
502  static struct rtnl_link_ops ip6_link_ops __read_mostly = {