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. @@ -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. @@ -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. @@ -383,6 +394,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. @@ -779,6 +796,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. @@ -831,6 +949,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. @@ -962,6 +1101,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. @@ -1305,6 +1445,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. @@ -1371,6 +1512,18 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, str
  294. fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
  295. + /* try to find matching FMR */
  296. + for (fmr = t->parms.fmrs; fmr; fmr = fmr->next) {
  297. + unsigned mshift = 32 - fmr->ip4_prefix_len;
  298. + if (ntohl(fmr->ip4_prefix.s_addr) >> mshift ==
  299. + ntohl(ip_hdr(skb)->daddr) >> mshift)
  300. + break;
  301. + }
  302. +
  303. + /* change dstaddr according to FMR */
  304. + if (fmr)
  305. + ip4ip6_fmr_calc(&fl6.daddr, ip_hdr(skb), skb_tail_pointer(skb), fmr, true);
  306. +
  307. if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))
  308. return -1;
  309. @@ -1499,6 +1652,14 @@ ip6_tnl_change(struct ip6_tnl *t, const
  310. t->parms.link = p->link;
  311. t->parms.proto = p->proto;
  312. t->parms.fwmark = p->fwmark;
  313. +
  314. + while (t->parms.fmrs) {
  315. + struct __ip6_tnl_fmr *next = t->parms.fmrs->next;
  316. + kfree(t->parms.fmrs);
  317. + t->parms.fmrs = next;
  318. + }
  319. + t->parms.fmrs = p->fmrs;
  320. +
  321. dst_cache_reset(&t->dst_cache);
  322. ip6_tnl_link_config(t);
  323. return 0;
  324. @@ -1537,6 +1698,7 @@ ip6_tnl_parm_from_user(struct __ip6_tnl_
  325. p->flowinfo = u->flowinfo;
  326. p->link = u->link;
  327. p->proto = u->proto;
  328. + p->fmrs = NULL;
  329. memcpy(p->name, u->name, sizeof(u->name));
  330. }
  331. @@ -1923,6 +2085,15 @@ static int ip6_tnl_validate(struct nlatt
  332. return 0;
  333. }
  334. +static const struct nla_policy ip6_tnl_fmr_policy[IFLA_IPTUN_FMR_MAX + 1] = {
  335. + [IFLA_IPTUN_FMR_IP6_PREFIX] = { .len = sizeof(struct in6_addr) },
  336. + [IFLA_IPTUN_FMR_IP4_PREFIX] = { .len = sizeof(struct in_addr) },
  337. + [IFLA_IPTUN_FMR_IP6_PREFIX_LEN] = { .type = NLA_U8 },
  338. + [IFLA_IPTUN_FMR_IP4_PREFIX_LEN] = { .type = NLA_U8 },
  339. + [IFLA_IPTUN_FMR_EA_LEN] = { .type = NLA_U8 },
  340. + [IFLA_IPTUN_FMR_OFFSET] = { .type = NLA_U8 }
  341. +};
  342. +
  343. static void ip6_tnl_netlink_parms(struct nlattr *data[],
  344. struct __ip6_tnl_parm *parms)
  345. {
  346. @@ -1960,6 +2131,46 @@ static void ip6_tnl_netlink_parms(struct
  347. if (data[IFLA_IPTUN_FWMARK])
  348. parms->fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
  349. +
  350. + if (data[IFLA_IPTUN_FMRS]) {
  351. + unsigned rem;
  352. + struct nlattr *fmr;
  353. + nla_for_each_nested(fmr, data[IFLA_IPTUN_FMRS], rem) {
  354. + struct nlattr *fmrd[IFLA_IPTUN_FMR_MAX + 1], *c;
  355. + struct __ip6_tnl_fmr *nfmr;
  356. +
  357. + nla_parse_nested(fmrd, IFLA_IPTUN_FMR_MAX,
  358. + fmr, ip6_tnl_fmr_policy, NULL);
  359. +
  360. + if (!(nfmr = kzalloc(sizeof(*nfmr), GFP_KERNEL)))
  361. + continue;
  362. +
  363. + nfmr->offset = 6;
  364. +
  365. + if ((c = fmrd[IFLA_IPTUN_FMR_IP6_PREFIX]))
  366. + nla_memcpy(&nfmr->ip6_prefix, fmrd[IFLA_IPTUN_FMR_IP6_PREFIX],
  367. + sizeof(nfmr->ip6_prefix));
  368. +
  369. + if ((c = fmrd[IFLA_IPTUN_FMR_IP4_PREFIX]))
  370. + nla_memcpy(&nfmr->ip4_prefix, fmrd[IFLA_IPTUN_FMR_IP4_PREFIX],
  371. + sizeof(nfmr->ip4_prefix));
  372. +
  373. + if ((c = fmrd[IFLA_IPTUN_FMR_IP6_PREFIX_LEN]))
  374. + nfmr->ip6_prefix_len = nla_get_u8(c);
  375. +
  376. + if ((c = fmrd[IFLA_IPTUN_FMR_IP4_PREFIX_LEN]))
  377. + nfmr->ip4_prefix_len = nla_get_u8(c);
  378. +
  379. + if ((c = fmrd[IFLA_IPTUN_FMR_EA_LEN]))
  380. + nfmr->ea_len = nla_get_u8(c);
  381. +
  382. + if ((c = fmrd[IFLA_IPTUN_FMR_OFFSET]))
  383. + nfmr->offset = nla_get_u8(c);
  384. +
  385. + nfmr->next = parms->fmrs;
  386. + parms->fmrs = nfmr;
  387. + }
  388. + }
  389. }
  390. static bool ip6_tnl_netlink_encap_parms(struct nlattr *data[],
  391. @@ -2075,6 +2286,12 @@ static void ip6_tnl_dellink(struct net_d
  392. static size_t ip6_tnl_get_size(const struct net_device *dev)
  393. {
  394. + const struct ip6_tnl *t = netdev_priv(dev);
  395. + struct __ip6_tnl_fmr *c;
  396. + int fmrs = 0;
  397. + for (c = t->parms.fmrs; c; c = c->next)
  398. + ++fmrs;
  399. +
  400. return
  401. /* IFLA_IPTUN_LINK */
  402. nla_total_size(4) +
  403. @@ -2104,6 +2321,24 @@ static size_t ip6_tnl_get_size(const str
  404. nla_total_size(0) +
  405. /* IFLA_IPTUN_FWMARK */
  406. nla_total_size(4) +
  407. + /* IFLA_IPTUN_FMRS */
  408. + nla_total_size(0) +
  409. + (
  410. + /* nest */
  411. + nla_total_size(0) +
  412. + /* IFLA_IPTUN_FMR_IP6_PREFIX */
  413. + nla_total_size(sizeof(struct in6_addr)) +
  414. + /* IFLA_IPTUN_FMR_IP4_PREFIX */
  415. + nla_total_size(sizeof(struct in_addr)) +
  416. + /* IFLA_IPTUN_FMR_EA_LEN */
  417. + nla_total_size(1) +
  418. + /* IFLA_IPTUN_FMR_IP6_PREFIX_LEN */
  419. + nla_total_size(1) +
  420. + /* IFLA_IPTUN_FMR_IP4_PREFIX_LEN */
  421. + nla_total_size(1) +
  422. + /* IFLA_IPTUN_FMR_OFFSET */
  423. + nla_total_size(1)
  424. + ) * fmrs +
  425. 0;
  426. }
  427. @@ -2111,6 +2346,9 @@ static int ip6_tnl_fill_info(struct sk_b
  428. {
  429. struct ip6_tnl *tunnel = netdev_priv(dev);
  430. struct __ip6_tnl_parm *parm = &tunnel->parms;
  431. + struct __ip6_tnl_fmr *c;
  432. + int fmrcnt = 0;
  433. + struct nlattr *fmrs;
  434. if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
  435. nla_put_in6_addr(skb, IFLA_IPTUN_LOCAL, &parm->laddr) ||
  436. @@ -2120,9 +2358,27 @@ static int ip6_tnl_fill_info(struct sk_b
  437. nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) ||
  438. nla_put_u32(skb, IFLA_IPTUN_FLAGS, parm->flags) ||
  439. nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->proto) ||
  440. - nla_put_u32(skb, IFLA_IPTUN_FWMARK, parm->fwmark))
  441. + nla_put_u32(skb, IFLA_IPTUN_FWMARK, parm->fwmark) ||
  442. + !(fmrs = nla_nest_start(skb, IFLA_IPTUN_FMRS)))
  443. goto nla_put_failure;
  444. + for (c = parm->fmrs; c; c = c->next) {
  445. + struct nlattr *fmr = nla_nest_start(skb, ++fmrcnt);
  446. + if (!fmr ||
  447. + nla_put(skb, IFLA_IPTUN_FMR_IP6_PREFIX,
  448. + sizeof(c->ip6_prefix), &c->ip6_prefix) ||
  449. + nla_put(skb, IFLA_IPTUN_FMR_IP4_PREFIX,
  450. + sizeof(c->ip4_prefix), &c->ip4_prefix) ||
  451. + nla_put_u8(skb, IFLA_IPTUN_FMR_IP6_PREFIX_LEN, c->ip6_prefix_len) ||
  452. + nla_put_u8(skb, IFLA_IPTUN_FMR_IP4_PREFIX_LEN, c->ip4_prefix_len) ||
  453. + nla_put_u8(skb, IFLA_IPTUN_FMR_EA_LEN, c->ea_len) ||
  454. + nla_put_u8(skb, IFLA_IPTUN_FMR_OFFSET, c->offset))
  455. + goto nla_put_failure;
  456. +
  457. + nla_nest_end(skb, fmr);
  458. + }
  459. + nla_nest_end(skb, fmrs);
  460. +
  461. if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE, tunnel->encap.type) ||
  462. nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT, tunnel->encap.sport) ||
  463. nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT, tunnel->encap.dport) ||
  464. @@ -2162,6 +2418,7 @@ static const struct nla_policy ip6_tnl_p
  465. [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
  466. [IFLA_IPTUN_COLLECT_METADATA] = { .type = NLA_FLAG },
  467. [IFLA_IPTUN_FWMARK] = { .type = NLA_U32 },
  468. + [IFLA_IPTUN_FMRS] = { .type = NLA_NESTED },
  469. };
  470. static struct rtnl_link_ops ip6_link_ops __read_mostly = {