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

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