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

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