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