7123c806460e2aff7438faa4cb1bbe7c454bc304
[openwrt.git] / target / linux / generic / patches-4.4 / 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 @@ -15,6 +15,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 @@ -25,6 +37,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 @@ -57,10 +57,23 @@ enum {
49         IFLA_IPTUN_ENCAP_FLAGS,
50         IFLA_IPTUN_ENCAP_SPORT,
51         IFLA_IPTUN_ENCAP_DPORT,
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 @@ -71,11 +73,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 -
92 -       return hash_32(hash, HASH_SIZE_SHIFT);
93 +       return hash_32(ipv6_addr_hash(addr), HASH_SIZE_SHIFT);
94  }
95  
96  static int ip6_tnl_dev_init(struct net_device *dev);
97 @@ -230,27 +230,36 @@ EXPORT_SYMBOL_GPL(ip6_tnl_dst_init);
98  static struct ip6_tnl *
99  ip6_tnl_lookup(struct net *net, const struct in6_addr *remote, const struct in6_addr *local)
100  {
101 -       unsigned int hash = HASH(remote, local);
102 +       unsigned int hash = HASH(local);
103         struct ip6_tnl *t;
104         struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
105         struct in6_addr any;
106 +       struct __ip6_tnl_fmr *fmr;
107  
108         for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
109 -               if (ipv6_addr_equal(local, &t->parms.laddr) &&
110 -                   ipv6_addr_equal(remote, &t->parms.raddr) &&
111 -                   (t->dev->flags & IFF_UP))
112 +               if (!ipv6_addr_equal(local, &t->parms.laddr) ||
113 +                               !(t->dev->flags & IFF_UP))
114 +                       continue;
115 +
116 +               if (ipv6_addr_equal(remote, &t->parms.raddr))
117                         return t;
118 +
119 +               for (fmr = t->parms.fmrs; fmr; fmr = fmr->next) {
120 +                       if (ipv6_prefix_equal(remote, &fmr->ip6_prefix,
121 +                                       fmr->ip6_prefix_len))
122 +                               return t;
123 +               }
124         }
125  
126         memset(&any, 0, sizeof(any));
127 -       hash = HASH(&any, local);
128 +       hash = HASH(local);
129         for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
130                 if (ipv6_addr_equal(local, &t->parms.laddr) &&
131                     (t->dev->flags & IFF_UP))
132                         return t;
133         }
134  
135 -       hash = HASH(remote, &any);
136 +       hash = HASH(&any);
137         for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
138                 if (ipv6_addr_equal(remote, &t->parms.raddr) &&
139                     (t->dev->flags & IFF_UP))
140 @@ -285,7 +294,7 @@ ip6_tnl_bucket(struct ip6_tnl_net *ip6n,
141  
142         if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
143                 prio = 1;
144 -               h = HASH(remote, local);
145 +               h = HASH(local);
146         }
147         return &ip6n->tnls[prio][h];
148  }
149 @@ -458,6 +467,12 @@ ip6_tnl_dev_uninit(struct net_device *de
150         struct net *net = t->net;
151         struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
152  
153 +       while (t->parms.fmrs) {
154 +               struct __ip6_tnl_fmr *next = t->parms.fmrs->next;
155 +               kfree(t->parms.fmrs);
156 +               t->parms.fmrs = next;
157 +       }
158 +
159         if (dev == ip6n->fb_tnl_dev)
160                 RCU_INIT_POINTER(ip6n->tnls_wc[0], NULL);
161         else
162 @@ -844,6 +859,108 @@ int ip6_tnl_rcv_ctl(struct ip6_tnl *t,
163  }
164  EXPORT_SYMBOL_GPL(ip6_tnl_rcv_ctl);
165  
166 +
167 +/**
168 + * ip4ip6_fmr_calc - calculate target / source IPv6-address based on FMR
169 + *   @dest: destination IPv6 address buffer
170 + *   @skb: received socket buffer
171 + *   @fmr: MAP FMR
172 + *   @xmit: Calculate for xmit or rcv
173 + **/
174 +static void ip4ip6_fmr_calc(struct in6_addr *dest,
175 +               const struct iphdr *iph, const uint8_t *end,
176 +               const struct __ip6_tnl_fmr *fmr, bool xmit)
177 +{
178 +       int psidlen = fmr->ea_len - (32 - fmr->ip4_prefix_len);
179 +       u8 *portp = NULL;
180 +       bool use_dest_addr;
181 +       const struct iphdr *dsth = iph;
182 +
183 +       if ((u8*)dsth >= end)
184 +               return;
185 +
186 +       /* find significant IP header */
187 +       if (iph->protocol == IPPROTO_ICMP) {
188 +               struct icmphdr *ih = (struct icmphdr*)(((u8*)dsth) + dsth->ihl * 4);
189 +               if (ih && ((u8*)&ih[1]) <= end && (
190 +                       ih->type == ICMP_DEST_UNREACH ||
191 +                       ih->type == ICMP_SOURCE_QUENCH ||
192 +                       ih->type == ICMP_TIME_EXCEEDED ||
193 +                       ih->type == ICMP_PARAMETERPROB ||
194 +                       ih->type == ICMP_REDIRECT))
195 +                               dsth = (const struct iphdr*)&ih[1];
196 +       }
197 +
198 +       /* in xmit-path use dest port by default and source port only if
199 +               this is an ICMP reply to something else; vice versa in rcv-path */
200 +       use_dest_addr = (xmit && dsth == iph) || (!xmit && dsth != iph);
201 +
202 +       /* get dst port */
203 +       if (((u8*)&dsth[1]) <= end && (
204 +               dsth->protocol == IPPROTO_UDP ||
205 +               dsth->protocol == IPPROTO_TCP ||
206 +               dsth->protocol == IPPROTO_SCTP ||
207 +               dsth->protocol == IPPROTO_DCCP)) {
208 +                       /* for UDP, TCP, SCTP and DCCP source and dest port
209 +                       follow IPv4 header directly */
210 +                       portp = ((u8*)dsth) + dsth->ihl * 4;
211 +
212 +                       if (use_dest_addr)
213 +                               portp += sizeof(u16);
214 +       } else if (iph->protocol == IPPROTO_ICMP) {
215 +               struct icmphdr *ih = (struct icmphdr*)(((u8*)dsth) + dsth->ihl * 4);
216 +
217 +               /* use icmp identifier as port */
218 +               if (((u8*)&ih) <= end && (
219 +                   (use_dest_addr && (
220 +                   ih->type == ICMP_ECHOREPLY ||
221 +                       ih->type == ICMP_TIMESTAMPREPLY ||
222 +                       ih->type == ICMP_INFO_REPLY ||
223 +                       ih->type == ICMP_ADDRESSREPLY)) ||
224 +                       (!use_dest_addr && (
225 +                       ih->type == ICMP_ECHO ||
226 +                       ih->type == ICMP_TIMESTAMP ||
227 +                       ih->type == ICMP_INFO_REQUEST ||
228 +                       ih->type == ICMP_ADDRESS)
229 +                       )))
230 +                               portp = (u8*)&ih->un.echo.id;
231 +       }
232 +
233 +       if ((portp && &portp[2] <= end) || psidlen == 0) {
234 +               int frombyte = fmr->ip6_prefix_len / 8;
235 +               int fromrem = fmr->ip6_prefix_len % 8;
236 +               int bytes = sizeof(struct in6_addr) - frombyte;
237 +               const u32 *addr = (use_dest_addr) ? &iph->daddr : &iph->saddr;
238 +               u64 eabits = ((u64)ntohl(*addr)) << (32 + fmr->ip4_prefix_len);
239 +               u64 t = 0;
240 +
241 +               /* extract PSID from port and add it to eabits */
242 +               u16 psidbits = 0;
243 +               if (psidlen > 0) {
244 +                       psidbits = ((u16)portp[0]) << 8 | ((u16)portp[1]);
245 +                       psidbits >>= 16 - psidlen - fmr->offset;
246 +                       psidbits = (u16)(psidbits << (16 - psidlen));
247 +                       eabits |= ((u64)psidbits) << (48 - (fmr->ea_len - psidlen));
248 +               }
249 +
250 +               /* rewrite destination address */
251 +               *dest = fmr->ip6_prefix;
252 +               memcpy(&dest->s6_addr[10], addr, sizeof(*addr));
253 +               dest->s6_addr16[7] = htons(psidbits >> (16 - psidlen));
254 +
255 +               if (bytes > sizeof(u64))
256 +                       bytes = sizeof(u64);
257 +
258 +               /* insert eabits */
259 +               memcpy(&t, &dest->s6_addr[frombyte], bytes);
260 +               t = be64_to_cpu(t) & ~(((((u64)1) << fmr->ea_len) - 1)
261 +                       << (64 - fmr->ea_len - fromrem));
262 +               t = cpu_to_be64(t | (eabits >> fromrem));
263 +               memcpy(&dest->s6_addr[frombyte], &t, bytes);
264 +       }
265 +}
266 +
267 +
268  /**
269   * ip6_tnl_rcv - decapsulate IPv6 packet and retransmit it locally
270   *   @skb: received socket buffer
271 @@ -889,6 +1006,26 @@ static int ip6_tnl_rcv(struct sk_buff *s
272                 skb_reset_network_header(skb);
273                 skb->protocol = htons(protocol);
274                 memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
275 +               if (protocol == ETH_P_IP &&
276 +                       !ipv6_addr_equal(&ipv6h->saddr, &t->parms.raddr)) {
277 +                               /* Packet didn't come from BR, so lookup FMR */
278 +                               struct __ip6_tnl_fmr *fmr;
279 +                               struct in6_addr expected = t->parms.raddr;
280 +                               for (fmr = t->parms.fmrs; fmr; fmr = fmr->next)
281 +                                       if (ipv6_prefix_equal(&ipv6h->saddr,
282 +                                               &fmr->ip6_prefix, fmr->ip6_prefix_len))
283 +                                                       break;
284 +
285 +                               /* Check that IPv6 matches IPv4 source to prevent spoofing */
286 +                               if (fmr)
287 +                                       ip4ip6_fmr_calc(&expected, ip_hdr(skb),
288 +                                                       skb_tail_pointer(skb), fmr, false);
289 +
290 +                               if (!ipv6_addr_equal(&ipv6h->saddr, &expected)) {
291 +                                       rcu_read_unlock();
292 +                                       goto discard;
293 +                               }
294 +               }
295  
296                 __skb_tunnel_rx(skb, t->dev, t->net);
297  
298 @@ -1179,6 +1316,7 @@ ip4ip6_tnl_xmit(struct sk_buff *skb, str
299         __u32 mtu;
300         u8 tproto;
301         int err;
302 +       struct __ip6_tnl_fmr *fmr;
303  
304         tproto = ACCESS_ONCE(t->parms.proto);
305         if (tproto != IPPROTO_IPIP && tproto != 0)
306 @@ -1198,6 +1336,18 @@ ip4ip6_tnl_xmit(struct sk_buff *skb, str
307         if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
308                 fl6.flowi6_mark = skb->mark;
309  
310 +       /* try to find matching FMR */
311 +       for (fmr = t->parms.fmrs; fmr; fmr = fmr->next) {
312 +               unsigned mshift = 32 - fmr->ip4_prefix_len;
313 +               if (ntohl(fmr->ip4_prefix.s_addr) >> mshift ==
314 +                               ntohl(iph->daddr) >> mshift)
315 +                       break;
316 +       }
317 +
318 +       /* change dstaddr according to FMR */
319 +       if (fmr)
320 +               ip4ip6_fmr_calc(&fl6.daddr, iph, skb_tail_pointer(skb), fmr, true);
321 +
322         err = ip6_tnl_xmit2(skb, dev, dsfield, &fl6, encap_limit, &mtu);
323         if (err != 0) {
324                 /* XXX: send ICMP error even if DF is not set. */
325 @@ -1366,6 +1516,14 @@ ip6_tnl_change(struct ip6_tnl *t, const
326         t->parms.flowinfo = p->flowinfo;
327         t->parms.link = p->link;
328         t->parms.proto = p->proto;
329 +
330 +       while (t->parms.fmrs) {
331 +               struct __ip6_tnl_fmr *next = t->parms.fmrs->next;
332 +               kfree(t->parms.fmrs);
333 +               t->parms.fmrs = next;
334 +       }
335 +       t->parms.fmrs = p->fmrs;
336 +
337         ip6_tnl_dst_reset(t);
338         ip6_tnl_link_config(t);
339         return 0;
340 @@ -1404,6 +1562,7 @@ ip6_tnl_parm_from_user(struct __ip6_tnl_
341         p->flowinfo = u->flowinfo;
342         p->link = u->link;
343         p->proto = u->proto;
344 +       p->fmrs = NULL;
345         memcpy(p->name, u->name, sizeof(u->name));
346  }
347  
348 @@ -1699,6 +1858,15 @@ static int ip6_tnl_validate(struct nlatt
349         return 0;
350  }
351  
352 +static const struct nla_policy ip6_tnl_fmr_policy[IFLA_IPTUN_FMR_MAX + 1] = {
353 +       [IFLA_IPTUN_FMR_IP6_PREFIX] = { .len = sizeof(struct in6_addr) },
354 +       [IFLA_IPTUN_FMR_IP4_PREFIX] = { .len = sizeof(struct in_addr) },
355 +       [IFLA_IPTUN_FMR_IP6_PREFIX_LEN] = { .type = NLA_U8 },
356 +       [IFLA_IPTUN_FMR_IP4_PREFIX_LEN] = { .type = NLA_U8 },
357 +       [IFLA_IPTUN_FMR_EA_LEN] = { .type = NLA_U8 },
358 +       [IFLA_IPTUN_FMR_OFFSET] = { .type = NLA_U8 }
359 +};
360 +
361  static void ip6_tnl_netlink_parms(struct nlattr *data[],
362                                   struct __ip6_tnl_parm *parms)
363  {
364 @@ -1730,6 +1898,46 @@ static void ip6_tnl_netlink_parms(struct
365  
366         if (data[IFLA_IPTUN_PROTO])
367                 parms->proto = nla_get_u8(data[IFLA_IPTUN_PROTO]);
368 +
369 +       if (data[IFLA_IPTUN_FMRS]) {
370 +               unsigned rem;
371 +               struct nlattr *fmr;
372 +               nla_for_each_nested(fmr, data[IFLA_IPTUN_FMRS], rem) {
373 +                       struct nlattr *fmrd[IFLA_IPTUN_FMR_MAX + 1], *c;
374 +                       struct __ip6_tnl_fmr *nfmr;
375 +
376 +                       nla_parse_nested(fmrd, IFLA_IPTUN_FMR_MAX,
377 +                               fmr, ip6_tnl_fmr_policy);
378 +
379 +                       if (!(nfmr = kzalloc(sizeof(*nfmr), GFP_KERNEL)))
380 +                               continue;
381 +
382 +                       nfmr->offset = 6;
383 +
384 +                       if ((c = fmrd[IFLA_IPTUN_FMR_IP6_PREFIX]))
385 +                               nla_memcpy(&nfmr->ip6_prefix, fmrd[IFLA_IPTUN_FMR_IP6_PREFIX],
386 +                                       sizeof(nfmr->ip6_prefix));
387 +
388 +                       if ((c = fmrd[IFLA_IPTUN_FMR_IP4_PREFIX]))
389 +                               nla_memcpy(&nfmr->ip4_prefix, fmrd[IFLA_IPTUN_FMR_IP4_PREFIX],
390 +                                       sizeof(nfmr->ip4_prefix));
391 +
392 +                       if ((c = fmrd[IFLA_IPTUN_FMR_IP6_PREFIX_LEN]))
393 +                               nfmr->ip6_prefix_len = nla_get_u8(c);
394 +
395 +                       if ((c = fmrd[IFLA_IPTUN_FMR_IP4_PREFIX_LEN]))
396 +                               nfmr->ip4_prefix_len = nla_get_u8(c);
397 +
398 +                       if ((c = fmrd[IFLA_IPTUN_FMR_EA_LEN]))
399 +                               nfmr->ea_len = nla_get_u8(c);
400 +
401 +                       if ((c = fmrd[IFLA_IPTUN_FMR_OFFSET]))
402 +                               nfmr->offset = nla_get_u8(c);
403 +
404 +                       nfmr->next = parms->fmrs;
405 +                       parms->fmrs = nfmr;
406 +               }
407 +       }
408  }
409  
410  static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
411 @@ -1782,6 +1990,12 @@ static void ip6_tnl_dellink(struct net_d
412  
413  static size_t ip6_tnl_get_size(const struct net_device *dev)
414  {
415 +       const struct ip6_tnl *t = netdev_priv(dev);
416 +       struct __ip6_tnl_fmr *c;
417 +       int fmrs = 0;
418 +       for (c = t->parms.fmrs; c; c = c->next)
419 +               ++fmrs;
420 +
421         return
422                 /* IFLA_IPTUN_LINK */
423                 nla_total_size(4) +
424 @@ -1799,6 +2013,24 @@ static size_t ip6_tnl_get_size(const str
425                 nla_total_size(4) +
426                 /* IFLA_IPTUN_PROTO */
427                 nla_total_size(1) +
428 +               /* IFLA_IPTUN_FMRS */
429 +               nla_total_size(0) +
430 +               (
431 +                       /* nest */
432 +                       nla_total_size(0) +
433 +                       /* IFLA_IPTUN_FMR_IP6_PREFIX */
434 +                       nla_total_size(sizeof(struct in6_addr)) +
435 +                       /* IFLA_IPTUN_FMR_IP4_PREFIX */
436 +                       nla_total_size(sizeof(struct in_addr)) +
437 +                       /* IFLA_IPTUN_FMR_EA_LEN */
438 +                       nla_total_size(1) +
439 +                       /* IFLA_IPTUN_FMR_IP6_PREFIX_LEN */
440 +                       nla_total_size(1) +
441 +                       /* IFLA_IPTUN_FMR_IP4_PREFIX_LEN */
442 +                       nla_total_size(1) +
443 +                       /* IFLA_IPTUN_FMR_OFFSET */
444 +                       nla_total_size(1)
445 +               ) * fmrs +
446                 0;
447  }
448  
449 @@ -1806,6 +2038,9 @@ static int ip6_tnl_fill_info(struct sk_b
450  {
451         struct ip6_tnl *tunnel = netdev_priv(dev);
452         struct __ip6_tnl_parm *parm = &tunnel->parms;
453 +       struct __ip6_tnl_fmr *c;
454 +       int fmrcnt = 0;
455 +       struct nlattr *fmrs;
456  
457         if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
458             nla_put_in6_addr(skb, IFLA_IPTUN_LOCAL, &parm->laddr) ||
459 @@ -1814,8 +2049,27 @@ static int ip6_tnl_fill_info(struct sk_b
460             nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) ||
461             nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) ||
462             nla_put_u32(skb, IFLA_IPTUN_FLAGS, parm->flags) ||
463 -           nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->proto))
464 +           nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->proto) ||
465 +           !(fmrs = nla_nest_start(skb, IFLA_IPTUN_FMRS)))
466                 goto nla_put_failure;
467 +
468 +       for (c = parm->fmrs; c; c = c->next) {
469 +               struct nlattr *fmr = nla_nest_start(skb, ++fmrcnt);
470 +               if (!fmr ||
471 +                       nla_put(skb, IFLA_IPTUN_FMR_IP6_PREFIX,
472 +                               sizeof(c->ip6_prefix), &c->ip6_prefix) ||
473 +                       nla_put(skb, IFLA_IPTUN_FMR_IP4_PREFIX,
474 +                               sizeof(c->ip4_prefix), &c->ip4_prefix) ||
475 +                       nla_put_u8(skb, IFLA_IPTUN_FMR_IP6_PREFIX_LEN, c->ip6_prefix_len) ||
476 +                       nla_put_u8(skb, IFLA_IPTUN_FMR_IP4_PREFIX_LEN, c->ip4_prefix_len) ||
477 +                       nla_put_u8(skb, IFLA_IPTUN_FMR_EA_LEN, c->ea_len) ||
478 +                       nla_put_u8(skb, IFLA_IPTUN_FMR_OFFSET, c->offset))
479 +                               goto nla_put_failure;
480 +
481 +               nla_nest_end(skb, fmr);
482 +       }
483 +       nla_nest_end(skb, fmrs);
484 +
485         return 0;
486  
487  nla_put_failure:
488 @@ -1839,6 +2093,7 @@ static const struct nla_policy ip6_tnl_p
489         [IFLA_IPTUN_FLOWINFO]           = { .type = NLA_U32 },
490         [IFLA_IPTUN_FLAGS]              = { .type = NLA_U32 },
491         [IFLA_IPTUN_PROTO]              = { .type = NLA_U8 },
492 +       [IFLA_IPTUN_FMRS]               = { .type = NLA_NESTED },
493  };
494  
495  static struct rtnl_link_ops ip6_link_ops __read_mostly = {