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