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

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