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

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