1
0

666-Add-support-for-MAP-E-FMRs-mesh-mode.patch 15 KB

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