2
0

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

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