actions.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. /*
  2. * Copyright (c) 2007-2014 Nicira, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of version 2 of the GNU General Public
  6. * License as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301, USA
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/skbuff.h>
  20. #include <linux/in.h>
  21. #include <linux/ip.h>
  22. #include <linux/openvswitch.h>
  23. #include <linux/netfilter_ipv6.h>
  24. #include <linux/sctp.h>
  25. #include <linux/tcp.h>
  26. #include <linux/udp.h>
  27. #include <linux/in6.h>
  28. #include <linux/if_arp.h>
  29. #include <linux/if_vlan.h>
  30. #include <net/dst.h>
  31. #include <net/ip.h>
  32. #include <net/ipv6.h>
  33. #include <net/ip6_fib.h>
  34. #include <net/checksum.h>
  35. #include <net/dsfield.h>
  36. #include <net/mpls.h>
  37. #include <net/sctp/checksum.h>
  38. #include "datapath.h"
  39. #include "flow.h"
  40. #include "conntrack.h"
  41. #include "vport.h"
  42. static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
  43. struct sw_flow_key *key,
  44. const struct nlattr *attr, int len);
  45. struct deferred_action {
  46. struct sk_buff *skb;
  47. const struct nlattr *actions;
  48. /* Store pkt_key clone when creating deferred action. */
  49. struct sw_flow_key pkt_key;
  50. };
  51. #define MAX_L2_LEN (VLAN_ETH_HLEN + 3 * MPLS_HLEN)
  52. struct ovs_frag_data {
  53. unsigned long dst;
  54. struct vport *vport;
  55. struct ovs_skb_cb cb;
  56. __be16 inner_protocol;
  57. __u16 vlan_tci;
  58. __be16 vlan_proto;
  59. unsigned int l2_len;
  60. u8 l2_data[MAX_L2_LEN];
  61. };
  62. static DEFINE_PER_CPU(struct ovs_frag_data, ovs_frag_data_storage);
  63. #define DEFERRED_ACTION_FIFO_SIZE 10
  64. #define OVS_RECURSION_LIMIT 5
  65. #define OVS_DEFERRED_ACTION_THRESHOLD (OVS_RECURSION_LIMIT - 2)
  66. struct action_fifo {
  67. int head;
  68. int tail;
  69. /* Deferred action fifo queue storage. */
  70. struct deferred_action fifo[DEFERRED_ACTION_FIFO_SIZE];
  71. };
  72. struct recirc_keys {
  73. struct sw_flow_key key[OVS_DEFERRED_ACTION_THRESHOLD];
  74. };
  75. static struct action_fifo __percpu *action_fifos;
  76. static struct recirc_keys __percpu *recirc_keys;
  77. static DEFINE_PER_CPU(int, exec_actions_level);
  78. static void action_fifo_init(struct action_fifo *fifo)
  79. {
  80. fifo->head = 0;
  81. fifo->tail = 0;
  82. }
  83. static bool action_fifo_is_empty(const struct action_fifo *fifo)
  84. {
  85. return (fifo->head == fifo->tail);
  86. }
  87. static struct deferred_action *action_fifo_get(struct action_fifo *fifo)
  88. {
  89. if (action_fifo_is_empty(fifo))
  90. return NULL;
  91. return &fifo->fifo[fifo->tail++];
  92. }
  93. static struct deferred_action *action_fifo_put(struct action_fifo *fifo)
  94. {
  95. if (fifo->head >= DEFERRED_ACTION_FIFO_SIZE - 1)
  96. return NULL;
  97. return &fifo->fifo[fifo->head++];
  98. }
  99. /* Return true if fifo is not full */
  100. static struct deferred_action *add_deferred_actions(struct sk_buff *skb,
  101. const struct sw_flow_key *key,
  102. const struct nlattr *attr)
  103. {
  104. struct action_fifo *fifo;
  105. struct deferred_action *da;
  106. fifo = this_cpu_ptr(action_fifos);
  107. da = action_fifo_put(fifo);
  108. if (da) {
  109. da->skb = skb;
  110. da->actions = attr;
  111. da->pkt_key = *key;
  112. }
  113. return da;
  114. }
  115. static void invalidate_flow_key(struct sw_flow_key *key)
  116. {
  117. key->eth.type = htons(0);
  118. }
  119. static bool is_flow_key_valid(const struct sw_flow_key *key)
  120. {
  121. return !!key->eth.type;
  122. }
  123. static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr,
  124. __be16 ethertype)
  125. {
  126. if (skb->ip_summed == CHECKSUM_COMPLETE) {
  127. __be16 diff[] = { ~(hdr->h_proto), ethertype };
  128. skb->csum = ~csum_partial((char *)diff, sizeof(diff),
  129. ~skb->csum);
  130. }
  131. hdr->h_proto = ethertype;
  132. }
  133. static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
  134. const struct ovs_action_push_mpls *mpls)
  135. {
  136. struct mpls_shim_hdr *new_mpls_lse;
  137. /* Networking stack do not allow simultaneous Tunnel and MPLS GSO. */
  138. if (skb->encapsulation)
  139. return -ENOTSUPP;
  140. if (skb_cow_head(skb, MPLS_HLEN) < 0)
  141. return -ENOMEM;
  142. if (!skb->inner_protocol) {
  143. skb_set_inner_network_header(skb, skb->mac_len);
  144. skb_set_inner_protocol(skb, skb->protocol);
  145. }
  146. skb_push(skb, MPLS_HLEN);
  147. memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb),
  148. skb->mac_len);
  149. skb_reset_mac_header(skb);
  150. skb_set_network_header(skb, skb->mac_len);
  151. new_mpls_lse = mpls_hdr(skb);
  152. new_mpls_lse->label_stack_entry = mpls->mpls_lse;
  153. skb_postpush_rcsum(skb, new_mpls_lse, MPLS_HLEN);
  154. update_ethertype(skb, eth_hdr(skb), mpls->mpls_ethertype);
  155. skb->protocol = mpls->mpls_ethertype;
  156. invalidate_flow_key(key);
  157. return 0;
  158. }
  159. static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
  160. const __be16 ethertype)
  161. {
  162. struct ethhdr *hdr;
  163. int err;
  164. err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
  165. if (unlikely(err))
  166. return err;
  167. skb_postpull_rcsum(skb, mpls_hdr(skb), MPLS_HLEN);
  168. memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
  169. skb->mac_len);
  170. __skb_pull(skb, MPLS_HLEN);
  171. skb_reset_mac_header(skb);
  172. skb_set_network_header(skb, skb->mac_len);
  173. /* mpls_hdr() is used to locate the ethertype field correctly in the
  174. * presence of VLAN tags.
  175. */
  176. hdr = (struct ethhdr *)((void *)mpls_hdr(skb) - ETH_HLEN);
  177. update_ethertype(skb, hdr, ethertype);
  178. if (eth_p_mpls(skb->protocol))
  179. skb->protocol = ethertype;
  180. invalidate_flow_key(key);
  181. return 0;
  182. }
  183. static int set_mpls(struct sk_buff *skb, struct sw_flow_key *flow_key,
  184. const __be32 *mpls_lse, const __be32 *mask)
  185. {
  186. struct mpls_shim_hdr *stack;
  187. __be32 lse;
  188. int err;
  189. err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
  190. if (unlikely(err))
  191. return err;
  192. stack = mpls_hdr(skb);
  193. lse = OVS_MASKED(stack->label_stack_entry, *mpls_lse, *mask);
  194. if (skb->ip_summed == CHECKSUM_COMPLETE) {
  195. __be32 diff[] = { ~(stack->label_stack_entry), lse };
  196. skb->csum = ~csum_partial((char *)diff, sizeof(diff),
  197. ~skb->csum);
  198. }
  199. stack->label_stack_entry = lse;
  200. flow_key->mpls.top_lse = lse;
  201. return 0;
  202. }
  203. static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
  204. {
  205. int err;
  206. err = skb_vlan_pop(skb);
  207. if (skb_vlan_tag_present(skb)) {
  208. invalidate_flow_key(key);
  209. } else {
  210. key->eth.vlan.tci = 0;
  211. key->eth.vlan.tpid = 0;
  212. }
  213. return err;
  214. }
  215. static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
  216. const struct ovs_action_push_vlan *vlan)
  217. {
  218. if (skb_vlan_tag_present(skb)) {
  219. invalidate_flow_key(key);
  220. } else {
  221. key->eth.vlan.tci = vlan->vlan_tci;
  222. key->eth.vlan.tpid = vlan->vlan_tpid;
  223. }
  224. return skb_vlan_push(skb, vlan->vlan_tpid,
  225. ntohs(vlan->vlan_tci) & ~VLAN_TAG_PRESENT);
  226. }
  227. /* 'src' is already properly masked. */
  228. static void ether_addr_copy_masked(u8 *dst_, const u8 *src_, const u8 *mask_)
  229. {
  230. u16 *dst = (u16 *)dst_;
  231. const u16 *src = (const u16 *)src_;
  232. const u16 *mask = (const u16 *)mask_;
  233. OVS_SET_MASKED(dst[0], src[0], mask[0]);
  234. OVS_SET_MASKED(dst[1], src[1], mask[1]);
  235. OVS_SET_MASKED(dst[2], src[2], mask[2]);
  236. }
  237. static int set_eth_addr(struct sk_buff *skb, struct sw_flow_key *flow_key,
  238. const struct ovs_key_ethernet *key,
  239. const struct ovs_key_ethernet *mask)
  240. {
  241. int err;
  242. err = skb_ensure_writable(skb, ETH_HLEN);
  243. if (unlikely(err))
  244. return err;
  245. skb_postpull_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
  246. ether_addr_copy_masked(eth_hdr(skb)->h_source, key->eth_src,
  247. mask->eth_src);
  248. ether_addr_copy_masked(eth_hdr(skb)->h_dest, key->eth_dst,
  249. mask->eth_dst);
  250. skb_postpush_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
  251. ether_addr_copy(flow_key->eth.src, eth_hdr(skb)->h_source);
  252. ether_addr_copy(flow_key->eth.dst, eth_hdr(skb)->h_dest);
  253. return 0;
  254. }
  255. static void update_ip_l4_checksum(struct sk_buff *skb, struct iphdr *nh,
  256. __be32 addr, __be32 new_addr)
  257. {
  258. int transport_len = skb->len - skb_transport_offset(skb);
  259. if (nh->frag_off & htons(IP_OFFSET))
  260. return;
  261. if (nh->protocol == IPPROTO_TCP) {
  262. if (likely(transport_len >= sizeof(struct tcphdr)))
  263. inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb,
  264. addr, new_addr, true);
  265. } else if (nh->protocol == IPPROTO_UDP) {
  266. if (likely(transport_len >= sizeof(struct udphdr))) {
  267. struct udphdr *uh = udp_hdr(skb);
  268. if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
  269. inet_proto_csum_replace4(&uh->check, skb,
  270. addr, new_addr, true);
  271. if (!uh->check)
  272. uh->check = CSUM_MANGLED_0;
  273. }
  274. }
  275. }
  276. }
  277. static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,
  278. __be32 *addr, __be32 new_addr)
  279. {
  280. update_ip_l4_checksum(skb, nh, *addr, new_addr);
  281. csum_replace4(&nh->check, *addr, new_addr);
  282. skb_clear_hash(skb);
  283. *addr = new_addr;
  284. }
  285. static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
  286. __be32 addr[4], const __be32 new_addr[4])
  287. {
  288. int transport_len = skb->len - skb_transport_offset(skb);
  289. if (l4_proto == NEXTHDR_TCP) {
  290. if (likely(transport_len >= sizeof(struct tcphdr)))
  291. inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
  292. addr, new_addr, true);
  293. } else if (l4_proto == NEXTHDR_UDP) {
  294. if (likely(transport_len >= sizeof(struct udphdr))) {
  295. struct udphdr *uh = udp_hdr(skb);
  296. if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
  297. inet_proto_csum_replace16(&uh->check, skb,
  298. addr, new_addr, true);
  299. if (!uh->check)
  300. uh->check = CSUM_MANGLED_0;
  301. }
  302. }
  303. } else if (l4_proto == NEXTHDR_ICMP) {
  304. if (likely(transport_len >= sizeof(struct icmp6hdr)))
  305. inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum,
  306. skb, addr, new_addr, true);
  307. }
  308. }
  309. static void mask_ipv6_addr(const __be32 old[4], const __be32 addr[4],
  310. const __be32 mask[4], __be32 masked[4])
  311. {
  312. masked[0] = OVS_MASKED(old[0], addr[0], mask[0]);
  313. masked[1] = OVS_MASKED(old[1], addr[1], mask[1]);
  314. masked[2] = OVS_MASKED(old[2], addr[2], mask[2]);
  315. masked[3] = OVS_MASKED(old[3], addr[3], mask[3]);
  316. }
  317. static void set_ipv6_addr(struct sk_buff *skb, u8 l4_proto,
  318. __be32 addr[4], const __be32 new_addr[4],
  319. bool recalculate_csum)
  320. {
  321. if (recalculate_csum)
  322. update_ipv6_checksum(skb, l4_proto, addr, new_addr);
  323. skb_clear_hash(skb);
  324. memcpy(addr, new_addr, sizeof(__be32[4]));
  325. }
  326. static void set_ipv6_fl(struct ipv6hdr *nh, u32 fl, u32 mask)
  327. {
  328. /* Bits 21-24 are always unmasked, so this retains their values. */
  329. OVS_SET_MASKED(nh->flow_lbl[0], (u8)(fl >> 16), (u8)(mask >> 16));
  330. OVS_SET_MASKED(nh->flow_lbl[1], (u8)(fl >> 8), (u8)(mask >> 8));
  331. OVS_SET_MASKED(nh->flow_lbl[2], (u8)fl, (u8)mask);
  332. }
  333. static void set_ip_ttl(struct sk_buff *skb, struct iphdr *nh, u8 new_ttl,
  334. u8 mask)
  335. {
  336. new_ttl = OVS_MASKED(nh->ttl, new_ttl, mask);
  337. csum_replace2(&nh->check, htons(nh->ttl << 8), htons(new_ttl << 8));
  338. nh->ttl = new_ttl;
  339. }
  340. static int set_ipv4(struct sk_buff *skb, struct sw_flow_key *flow_key,
  341. const struct ovs_key_ipv4 *key,
  342. const struct ovs_key_ipv4 *mask)
  343. {
  344. struct iphdr *nh;
  345. __be32 new_addr;
  346. int err;
  347. err = skb_ensure_writable(skb, skb_network_offset(skb) +
  348. sizeof(struct iphdr));
  349. if (unlikely(err))
  350. return err;
  351. nh = ip_hdr(skb);
  352. /* Setting an IP addresses is typically only a side effect of
  353. * matching on them in the current userspace implementation, so it
  354. * makes sense to check if the value actually changed.
  355. */
  356. if (mask->ipv4_src) {
  357. new_addr = OVS_MASKED(nh->saddr, key->ipv4_src, mask->ipv4_src);
  358. if (unlikely(new_addr != nh->saddr)) {
  359. set_ip_addr(skb, nh, &nh->saddr, new_addr);
  360. flow_key->ipv4.addr.src = new_addr;
  361. }
  362. }
  363. if (mask->ipv4_dst) {
  364. new_addr = OVS_MASKED(nh->daddr, key->ipv4_dst, mask->ipv4_dst);
  365. if (unlikely(new_addr != nh->daddr)) {
  366. set_ip_addr(skb, nh, &nh->daddr, new_addr);
  367. flow_key->ipv4.addr.dst = new_addr;
  368. }
  369. }
  370. if (mask->ipv4_tos) {
  371. ipv4_change_dsfield(nh, ~mask->ipv4_tos, key->ipv4_tos);
  372. flow_key->ip.tos = nh->tos;
  373. }
  374. if (mask->ipv4_ttl) {
  375. set_ip_ttl(skb, nh, key->ipv4_ttl, mask->ipv4_ttl);
  376. flow_key->ip.ttl = nh->ttl;
  377. }
  378. return 0;
  379. }
  380. static bool is_ipv6_mask_nonzero(const __be32 addr[4])
  381. {
  382. return !!(addr[0] | addr[1] | addr[2] | addr[3]);
  383. }
  384. static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key,
  385. const struct ovs_key_ipv6 *key,
  386. const struct ovs_key_ipv6 *mask)
  387. {
  388. struct ipv6hdr *nh;
  389. int err;
  390. err = skb_ensure_writable(skb, skb_network_offset(skb) +
  391. sizeof(struct ipv6hdr));
  392. if (unlikely(err))
  393. return err;
  394. nh = ipv6_hdr(skb);
  395. /* Setting an IP addresses is typically only a side effect of
  396. * matching on them in the current userspace implementation, so it
  397. * makes sense to check if the value actually changed.
  398. */
  399. if (is_ipv6_mask_nonzero(mask->ipv6_src)) {
  400. __be32 *saddr = (__be32 *)&nh->saddr;
  401. __be32 masked[4];
  402. mask_ipv6_addr(saddr, key->ipv6_src, mask->ipv6_src, masked);
  403. if (unlikely(memcmp(saddr, masked, sizeof(masked)))) {
  404. set_ipv6_addr(skb, flow_key->ip.proto, saddr, masked,
  405. true);
  406. memcpy(&flow_key->ipv6.addr.src, masked,
  407. sizeof(flow_key->ipv6.addr.src));
  408. }
  409. }
  410. if (is_ipv6_mask_nonzero(mask->ipv6_dst)) {
  411. unsigned int offset = 0;
  412. int flags = IP6_FH_F_SKIP_RH;
  413. bool recalc_csum = true;
  414. __be32 *daddr = (__be32 *)&nh->daddr;
  415. __be32 masked[4];
  416. mask_ipv6_addr(daddr, key->ipv6_dst, mask->ipv6_dst, masked);
  417. if (unlikely(memcmp(daddr, masked, sizeof(masked)))) {
  418. if (ipv6_ext_hdr(nh->nexthdr))
  419. recalc_csum = (ipv6_find_hdr(skb, &offset,
  420. NEXTHDR_ROUTING,
  421. NULL, &flags)
  422. != NEXTHDR_ROUTING);
  423. set_ipv6_addr(skb, flow_key->ip.proto, daddr, masked,
  424. recalc_csum);
  425. memcpy(&flow_key->ipv6.addr.dst, masked,
  426. sizeof(flow_key->ipv6.addr.dst));
  427. }
  428. }
  429. if (mask->ipv6_tclass) {
  430. ipv6_change_dsfield(nh, ~mask->ipv6_tclass, key->ipv6_tclass);
  431. flow_key->ip.tos = ipv6_get_dsfield(nh);
  432. }
  433. if (mask->ipv6_label) {
  434. set_ipv6_fl(nh, ntohl(key->ipv6_label),
  435. ntohl(mask->ipv6_label));
  436. flow_key->ipv6.label =
  437. *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL);
  438. }
  439. if (mask->ipv6_hlimit) {
  440. OVS_SET_MASKED(nh->hop_limit, key->ipv6_hlimit,
  441. mask->ipv6_hlimit);
  442. flow_key->ip.ttl = nh->hop_limit;
  443. }
  444. return 0;
  445. }
  446. /* Must follow skb_ensure_writable() since that can move the skb data. */
  447. static void set_tp_port(struct sk_buff *skb, __be16 *port,
  448. __be16 new_port, __sum16 *check)
  449. {
  450. inet_proto_csum_replace2(check, skb, *port, new_port, false);
  451. *port = new_port;
  452. }
  453. static int set_udp(struct sk_buff *skb, struct sw_flow_key *flow_key,
  454. const struct ovs_key_udp *key,
  455. const struct ovs_key_udp *mask)
  456. {
  457. struct udphdr *uh;
  458. __be16 src, dst;
  459. int err;
  460. err = skb_ensure_writable(skb, skb_transport_offset(skb) +
  461. sizeof(struct udphdr));
  462. if (unlikely(err))
  463. return err;
  464. uh = udp_hdr(skb);
  465. /* Either of the masks is non-zero, so do not bother checking them. */
  466. src = OVS_MASKED(uh->source, key->udp_src, mask->udp_src);
  467. dst = OVS_MASKED(uh->dest, key->udp_dst, mask->udp_dst);
  468. if (uh->check && skb->ip_summed != CHECKSUM_PARTIAL) {
  469. if (likely(src != uh->source)) {
  470. set_tp_port(skb, &uh->source, src, &uh->check);
  471. flow_key->tp.src = src;
  472. }
  473. if (likely(dst != uh->dest)) {
  474. set_tp_port(skb, &uh->dest, dst, &uh->check);
  475. flow_key->tp.dst = dst;
  476. }
  477. if (unlikely(!uh->check))
  478. uh->check = CSUM_MANGLED_0;
  479. } else {
  480. uh->source = src;
  481. uh->dest = dst;
  482. flow_key->tp.src = src;
  483. flow_key->tp.dst = dst;
  484. }
  485. skb_clear_hash(skb);
  486. return 0;
  487. }
  488. static int set_tcp(struct sk_buff *skb, struct sw_flow_key *flow_key,
  489. const struct ovs_key_tcp *key,
  490. const struct ovs_key_tcp *mask)
  491. {
  492. struct tcphdr *th;
  493. __be16 src, dst;
  494. int err;
  495. err = skb_ensure_writable(skb, skb_transport_offset(skb) +
  496. sizeof(struct tcphdr));
  497. if (unlikely(err))
  498. return err;
  499. th = tcp_hdr(skb);
  500. src = OVS_MASKED(th->source, key->tcp_src, mask->tcp_src);
  501. if (likely(src != th->source)) {
  502. set_tp_port(skb, &th->source, src, &th->check);
  503. flow_key->tp.src = src;
  504. }
  505. dst = OVS_MASKED(th->dest, key->tcp_dst, mask->tcp_dst);
  506. if (likely(dst != th->dest)) {
  507. set_tp_port(skb, &th->dest, dst, &th->check);
  508. flow_key->tp.dst = dst;
  509. }
  510. skb_clear_hash(skb);
  511. return 0;
  512. }
  513. static int set_sctp(struct sk_buff *skb, struct sw_flow_key *flow_key,
  514. const struct ovs_key_sctp *key,
  515. const struct ovs_key_sctp *mask)
  516. {
  517. unsigned int sctphoff = skb_transport_offset(skb);
  518. struct sctphdr *sh;
  519. __le32 old_correct_csum, new_csum, old_csum;
  520. int err;
  521. err = skb_ensure_writable(skb, sctphoff + sizeof(struct sctphdr));
  522. if (unlikely(err))
  523. return err;
  524. sh = sctp_hdr(skb);
  525. old_csum = sh->checksum;
  526. old_correct_csum = sctp_compute_cksum(skb, sctphoff);
  527. sh->source = OVS_MASKED(sh->source, key->sctp_src, mask->sctp_src);
  528. sh->dest = OVS_MASKED(sh->dest, key->sctp_dst, mask->sctp_dst);
  529. new_csum = sctp_compute_cksum(skb, sctphoff);
  530. /* Carry any checksum errors through. */
  531. sh->checksum = old_csum ^ old_correct_csum ^ new_csum;
  532. skb_clear_hash(skb);
  533. flow_key->tp.src = sh->source;
  534. flow_key->tp.dst = sh->dest;
  535. return 0;
  536. }
  537. static int ovs_vport_output(struct net *net, struct sock *sk, struct sk_buff *skb)
  538. {
  539. struct ovs_frag_data *data = this_cpu_ptr(&ovs_frag_data_storage);
  540. struct vport *vport = data->vport;
  541. if (skb_cow_head(skb, data->l2_len) < 0) {
  542. kfree_skb(skb);
  543. return -ENOMEM;
  544. }
  545. __skb_dst_copy(skb, data->dst);
  546. *OVS_CB(skb) = data->cb;
  547. skb->inner_protocol = data->inner_protocol;
  548. skb->vlan_tci = data->vlan_tci;
  549. skb->vlan_proto = data->vlan_proto;
  550. /* Reconstruct the MAC header. */
  551. skb_push(skb, data->l2_len);
  552. memcpy(skb->data, &data->l2_data, data->l2_len);
  553. skb_postpush_rcsum(skb, skb->data, data->l2_len);
  554. skb_reset_mac_header(skb);
  555. ovs_vport_send(vport, skb);
  556. return 0;
  557. }
  558. static unsigned int
  559. ovs_dst_get_mtu(const struct dst_entry *dst)
  560. {
  561. return dst->dev->mtu;
  562. }
  563. static struct dst_ops ovs_dst_ops = {
  564. .family = AF_UNSPEC,
  565. .mtu = ovs_dst_get_mtu,
  566. };
  567. /* prepare_frag() is called once per (larger-than-MTU) frame; its inverse is
  568. * ovs_vport_output(), which is called once per fragmented packet.
  569. */
  570. static void prepare_frag(struct vport *vport, struct sk_buff *skb)
  571. {
  572. unsigned int hlen = skb_network_offset(skb);
  573. struct ovs_frag_data *data;
  574. data = this_cpu_ptr(&ovs_frag_data_storage);
  575. data->dst = skb->_skb_refdst;
  576. data->vport = vport;
  577. data->cb = *OVS_CB(skb);
  578. data->inner_protocol = skb->inner_protocol;
  579. data->vlan_tci = skb->vlan_tci;
  580. data->vlan_proto = skb->vlan_proto;
  581. data->l2_len = hlen;
  582. memcpy(&data->l2_data, skb->data, hlen);
  583. memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
  584. skb_pull(skb, hlen);
  585. }
  586. static void ovs_fragment(struct net *net, struct vport *vport,
  587. struct sk_buff *skb, u16 mru, __be16 ethertype)
  588. {
  589. if (skb_network_offset(skb) > MAX_L2_LEN) {
  590. OVS_NLERR(1, "L2 header too long to fragment");
  591. goto err;
  592. }
  593. if (ethertype == htons(ETH_P_IP)) {
  594. struct dst_entry ovs_dst;
  595. unsigned long orig_dst;
  596. prepare_frag(vport, skb);
  597. dst_init(&ovs_dst, &ovs_dst_ops, NULL, 1,
  598. DST_OBSOLETE_NONE, DST_NOCOUNT);
  599. ovs_dst.dev = vport->dev;
  600. orig_dst = skb->_skb_refdst;
  601. skb_dst_set_noref(skb, &ovs_dst);
  602. IPCB(skb)->frag_max_size = mru;
  603. ip_do_fragment(net, skb->sk, skb, ovs_vport_output);
  604. refdst_drop(orig_dst);
  605. } else if (ethertype == htons(ETH_P_IPV6)) {
  606. const struct nf_ipv6_ops *v6ops = nf_get_ipv6_ops();
  607. unsigned long orig_dst;
  608. struct rt6_info ovs_rt;
  609. if (!v6ops) {
  610. goto err;
  611. }
  612. prepare_frag(vport, skb);
  613. memset(&ovs_rt, 0, sizeof(ovs_rt));
  614. dst_init(&ovs_rt.dst, &ovs_dst_ops, NULL, 1,
  615. DST_OBSOLETE_NONE, DST_NOCOUNT);
  616. ovs_rt.dst.dev = vport->dev;
  617. orig_dst = skb->_skb_refdst;
  618. skb_dst_set_noref(skb, &ovs_rt.dst);
  619. IP6CB(skb)->frag_max_size = mru;
  620. v6ops->fragment(net, skb->sk, skb, ovs_vport_output);
  621. refdst_drop(orig_dst);
  622. } else {
  623. WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.",
  624. ovs_vport_name(vport), ntohs(ethertype), mru,
  625. vport->dev->mtu);
  626. goto err;
  627. }
  628. return;
  629. err:
  630. kfree_skb(skb);
  631. }
  632. static void do_output(struct datapath *dp, struct sk_buff *skb, int out_port,
  633. struct sw_flow_key *key)
  634. {
  635. struct vport *vport = ovs_vport_rcu(dp, out_port);
  636. if (likely(vport)) {
  637. u16 mru = OVS_CB(skb)->mru;
  638. u32 cutlen = OVS_CB(skb)->cutlen;
  639. if (unlikely(cutlen > 0)) {
  640. if (skb->len - cutlen > ETH_HLEN)
  641. pskb_trim(skb, skb->len - cutlen);
  642. else
  643. pskb_trim(skb, ETH_HLEN);
  644. }
  645. if (likely(!mru || (skb->len <= mru + ETH_HLEN))) {
  646. ovs_vport_send(vport, skb);
  647. } else if (mru <= vport->dev->mtu) {
  648. struct net *net = read_pnet(&dp->net);
  649. __be16 ethertype = key->eth.type;
  650. if (!is_flow_key_valid(key)) {
  651. if (eth_p_mpls(skb->protocol))
  652. ethertype = skb->inner_protocol;
  653. else
  654. ethertype = vlan_get_protocol(skb);
  655. }
  656. ovs_fragment(net, vport, skb, mru, ethertype);
  657. } else {
  658. kfree_skb(skb);
  659. }
  660. } else {
  661. kfree_skb(skb);
  662. }
  663. }
  664. static int output_userspace(struct datapath *dp, struct sk_buff *skb,
  665. struct sw_flow_key *key, const struct nlattr *attr,
  666. const struct nlattr *actions, int actions_len,
  667. uint32_t cutlen)
  668. {
  669. struct dp_upcall_info upcall;
  670. const struct nlattr *a;
  671. int rem;
  672. memset(&upcall, 0, sizeof(upcall));
  673. upcall.cmd = OVS_PACKET_CMD_ACTION;
  674. upcall.mru = OVS_CB(skb)->mru;
  675. for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
  676. a = nla_next(a, &rem)) {
  677. switch (nla_type(a)) {
  678. case OVS_USERSPACE_ATTR_USERDATA:
  679. upcall.userdata = a;
  680. break;
  681. case OVS_USERSPACE_ATTR_PID:
  682. upcall.portid = nla_get_u32(a);
  683. break;
  684. case OVS_USERSPACE_ATTR_EGRESS_TUN_PORT: {
  685. /* Get out tunnel info. */
  686. struct vport *vport;
  687. vport = ovs_vport_rcu(dp, nla_get_u32(a));
  688. if (vport) {
  689. int err;
  690. err = dev_fill_metadata_dst(vport->dev, skb);
  691. if (!err)
  692. upcall.egress_tun_info = skb_tunnel_info(skb);
  693. }
  694. break;
  695. }
  696. case OVS_USERSPACE_ATTR_ACTIONS: {
  697. /* Include actions. */
  698. upcall.actions = actions;
  699. upcall.actions_len = actions_len;
  700. break;
  701. }
  702. } /* End of switch. */
  703. }
  704. return ovs_dp_upcall(dp, skb, key, &upcall, cutlen);
  705. }
  706. static int sample(struct datapath *dp, struct sk_buff *skb,
  707. struct sw_flow_key *key, const struct nlattr *attr,
  708. const struct nlattr *actions, int actions_len)
  709. {
  710. const struct nlattr *acts_list = NULL;
  711. const struct nlattr *a;
  712. int rem;
  713. u32 cutlen = 0;
  714. for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
  715. a = nla_next(a, &rem)) {
  716. u32 probability;
  717. switch (nla_type(a)) {
  718. case OVS_SAMPLE_ATTR_PROBABILITY:
  719. probability = nla_get_u32(a);
  720. if (!probability || prandom_u32() > probability)
  721. return 0;
  722. break;
  723. case OVS_SAMPLE_ATTR_ACTIONS:
  724. acts_list = a;
  725. break;
  726. }
  727. }
  728. rem = nla_len(acts_list);
  729. a = nla_data(acts_list);
  730. /* Actions list is empty, do nothing */
  731. if (unlikely(!rem))
  732. return 0;
  733. /* The only known usage of sample action is having a single user-space
  734. * action, or having a truncate action followed by a single user-space
  735. * action. Treat this usage as a special case.
  736. * The output_userspace() should clone the skb to be sent to the
  737. * user space. This skb will be consumed by its caller.
  738. */
  739. if (unlikely(nla_type(a) == OVS_ACTION_ATTR_TRUNC)) {
  740. struct ovs_action_trunc *trunc = nla_data(a);
  741. if (skb->len > trunc->max_len)
  742. cutlen = skb->len - trunc->max_len;
  743. a = nla_next(a, &rem);
  744. }
  745. if (likely(nla_type(a) == OVS_ACTION_ATTR_USERSPACE &&
  746. nla_is_last(a, rem)))
  747. return output_userspace(dp, skb, key, a, actions,
  748. actions_len, cutlen);
  749. skb = skb_clone(skb, GFP_ATOMIC);
  750. if (!skb)
  751. /* Skip the sample action when out of memory. */
  752. return 0;
  753. if (!add_deferred_actions(skb, key, a)) {
  754. if (net_ratelimit())
  755. pr_warn("%s: deferred actions limit reached, dropping sample action\n",
  756. ovs_dp_name(dp));
  757. kfree_skb(skb);
  758. }
  759. return 0;
  760. }
  761. static void execute_hash(struct sk_buff *skb, struct sw_flow_key *key,
  762. const struct nlattr *attr)
  763. {
  764. struct ovs_action_hash *hash_act = nla_data(attr);
  765. u32 hash = 0;
  766. /* OVS_HASH_ALG_L4 is the only possible hash algorithm. */
  767. hash = skb_get_hash(skb);
  768. hash = jhash_1word(hash, hash_act->hash_basis);
  769. if (!hash)
  770. hash = 0x1;
  771. key->ovs_flow_hash = hash;
  772. }
  773. static int execute_set_action(struct sk_buff *skb,
  774. struct sw_flow_key *flow_key,
  775. const struct nlattr *a)
  776. {
  777. /* Only tunnel set execution is supported without a mask. */
  778. if (nla_type(a) == OVS_KEY_ATTR_TUNNEL_INFO) {
  779. struct ovs_tunnel_info *tun = nla_data(a);
  780. skb_dst_drop(skb);
  781. dst_hold((struct dst_entry *)tun->tun_dst);
  782. skb_dst_set(skb, (struct dst_entry *)tun->tun_dst);
  783. return 0;
  784. }
  785. return -EINVAL;
  786. }
  787. /* Mask is at the midpoint of the data. */
  788. #define get_mask(a, type) ((const type)nla_data(a) + 1)
  789. static int execute_masked_set_action(struct sk_buff *skb,
  790. struct sw_flow_key *flow_key,
  791. const struct nlattr *a)
  792. {
  793. int err = 0;
  794. switch (nla_type(a)) {
  795. case OVS_KEY_ATTR_PRIORITY:
  796. OVS_SET_MASKED(skb->priority, nla_get_u32(a),
  797. *get_mask(a, u32 *));
  798. flow_key->phy.priority = skb->priority;
  799. break;
  800. case OVS_KEY_ATTR_SKB_MARK:
  801. OVS_SET_MASKED(skb->mark, nla_get_u32(a), *get_mask(a, u32 *));
  802. flow_key->phy.skb_mark = skb->mark;
  803. break;
  804. case OVS_KEY_ATTR_TUNNEL_INFO:
  805. /* Masked data not supported for tunnel. */
  806. err = -EINVAL;
  807. break;
  808. case OVS_KEY_ATTR_ETHERNET:
  809. err = set_eth_addr(skb, flow_key, nla_data(a),
  810. get_mask(a, struct ovs_key_ethernet *));
  811. break;
  812. case OVS_KEY_ATTR_IPV4:
  813. err = set_ipv4(skb, flow_key, nla_data(a),
  814. get_mask(a, struct ovs_key_ipv4 *));
  815. break;
  816. case OVS_KEY_ATTR_IPV6:
  817. err = set_ipv6(skb, flow_key, nla_data(a),
  818. get_mask(a, struct ovs_key_ipv6 *));
  819. break;
  820. case OVS_KEY_ATTR_TCP:
  821. err = set_tcp(skb, flow_key, nla_data(a),
  822. get_mask(a, struct ovs_key_tcp *));
  823. break;
  824. case OVS_KEY_ATTR_UDP:
  825. err = set_udp(skb, flow_key, nla_data(a),
  826. get_mask(a, struct ovs_key_udp *));
  827. break;
  828. case OVS_KEY_ATTR_SCTP:
  829. err = set_sctp(skb, flow_key, nla_data(a),
  830. get_mask(a, struct ovs_key_sctp *));
  831. break;
  832. case OVS_KEY_ATTR_MPLS:
  833. err = set_mpls(skb, flow_key, nla_data(a), get_mask(a,
  834. __be32 *));
  835. break;
  836. case OVS_KEY_ATTR_CT_STATE:
  837. case OVS_KEY_ATTR_CT_ZONE:
  838. case OVS_KEY_ATTR_CT_MARK:
  839. case OVS_KEY_ATTR_CT_LABELS:
  840. err = -EINVAL;
  841. break;
  842. }
  843. return err;
  844. }
  845. static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
  846. struct sw_flow_key *key,
  847. const struct nlattr *a, int rem)
  848. {
  849. struct deferred_action *da;
  850. int level;
  851. if (!is_flow_key_valid(key)) {
  852. int err;
  853. err = ovs_flow_key_update(skb, key);
  854. if (err)
  855. return err;
  856. }
  857. BUG_ON(!is_flow_key_valid(key));
  858. if (!nla_is_last(a, rem)) {
  859. /* Recirc action is the not the last action
  860. * of the action list, need to clone the skb.
  861. */
  862. skb = skb_clone(skb, GFP_ATOMIC);
  863. /* Skip the recirc action when out of memory, but
  864. * continue on with the rest of the action list.
  865. */
  866. if (!skb)
  867. return 0;
  868. }
  869. level = this_cpu_read(exec_actions_level);
  870. if (level <= OVS_DEFERRED_ACTION_THRESHOLD) {
  871. struct recirc_keys *rks = this_cpu_ptr(recirc_keys);
  872. struct sw_flow_key *recirc_key = &rks->key[level - 1];
  873. *recirc_key = *key;
  874. recirc_key->recirc_id = nla_get_u32(a);
  875. ovs_dp_process_packet(skb, recirc_key);
  876. return 0;
  877. }
  878. da = add_deferred_actions(skb, key, NULL);
  879. if (da) {
  880. da->pkt_key.recirc_id = nla_get_u32(a);
  881. } else {
  882. kfree_skb(skb);
  883. if (net_ratelimit())
  884. pr_warn("%s: deferred action limit reached, drop recirc action\n",
  885. ovs_dp_name(dp));
  886. }
  887. return 0;
  888. }
  889. /* Execute a list of actions against 'skb'. */
  890. static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
  891. struct sw_flow_key *key,
  892. const struct nlattr *attr, int len)
  893. {
  894. /* Every output action needs a separate clone of 'skb', but the common
  895. * case is just a single output action, so that doing a clone and
  896. * then freeing the original skbuff is wasteful. So the following code
  897. * is slightly obscure just to avoid that.
  898. */
  899. int prev_port = -1;
  900. const struct nlattr *a;
  901. int rem;
  902. for (a = attr, rem = len; rem > 0;
  903. a = nla_next(a, &rem)) {
  904. int err = 0;
  905. if (unlikely(prev_port != -1)) {
  906. struct sk_buff *out_skb = skb_clone(skb, GFP_ATOMIC);
  907. if (out_skb)
  908. do_output(dp, out_skb, prev_port, key);
  909. OVS_CB(skb)->cutlen = 0;
  910. prev_port = -1;
  911. }
  912. switch (nla_type(a)) {
  913. case OVS_ACTION_ATTR_OUTPUT:
  914. prev_port = nla_get_u32(a);
  915. break;
  916. case OVS_ACTION_ATTR_TRUNC: {
  917. struct ovs_action_trunc *trunc = nla_data(a);
  918. if (skb->len > trunc->max_len)
  919. OVS_CB(skb)->cutlen = skb->len - trunc->max_len;
  920. break;
  921. }
  922. case OVS_ACTION_ATTR_USERSPACE:
  923. output_userspace(dp, skb, key, a, attr,
  924. len, OVS_CB(skb)->cutlen);
  925. OVS_CB(skb)->cutlen = 0;
  926. break;
  927. case OVS_ACTION_ATTR_HASH:
  928. execute_hash(skb, key, a);
  929. break;
  930. case OVS_ACTION_ATTR_PUSH_MPLS:
  931. err = push_mpls(skb, key, nla_data(a));
  932. break;
  933. case OVS_ACTION_ATTR_POP_MPLS:
  934. err = pop_mpls(skb, key, nla_get_be16(a));
  935. break;
  936. case OVS_ACTION_ATTR_PUSH_VLAN:
  937. err = push_vlan(skb, key, nla_data(a));
  938. break;
  939. case OVS_ACTION_ATTR_POP_VLAN:
  940. err = pop_vlan(skb, key);
  941. break;
  942. case OVS_ACTION_ATTR_RECIRC:
  943. err = execute_recirc(dp, skb, key, a, rem);
  944. if (nla_is_last(a, rem)) {
  945. /* If this is the last action, the skb has
  946. * been consumed or freed.
  947. * Return immediately.
  948. */
  949. return err;
  950. }
  951. break;
  952. case OVS_ACTION_ATTR_SET:
  953. err = execute_set_action(skb, key, nla_data(a));
  954. break;
  955. case OVS_ACTION_ATTR_SET_MASKED:
  956. case OVS_ACTION_ATTR_SET_TO_MASKED:
  957. err = execute_masked_set_action(skb, key, nla_data(a));
  958. break;
  959. case OVS_ACTION_ATTR_SAMPLE:
  960. err = sample(dp, skb, key, a, attr, len);
  961. break;
  962. case OVS_ACTION_ATTR_CT:
  963. if (!is_flow_key_valid(key)) {
  964. err = ovs_flow_key_update(skb, key);
  965. if (err)
  966. return err;
  967. }
  968. err = ovs_ct_execute(ovs_dp_get_net(dp), skb, key,
  969. nla_data(a));
  970. /* Hide stolen IP fragments from user space. */
  971. if (err)
  972. return err == -EINPROGRESS ? 0 : err;
  973. break;
  974. }
  975. if (unlikely(err)) {
  976. kfree_skb(skb);
  977. return err;
  978. }
  979. }
  980. if (prev_port != -1)
  981. do_output(dp, skb, prev_port, key);
  982. else
  983. consume_skb(skb);
  984. return 0;
  985. }
  986. static void process_deferred_actions(struct datapath *dp)
  987. {
  988. struct action_fifo *fifo = this_cpu_ptr(action_fifos);
  989. /* Do not touch the FIFO in case there is no deferred actions. */
  990. if (action_fifo_is_empty(fifo))
  991. return;
  992. /* Finishing executing all deferred actions. */
  993. do {
  994. struct deferred_action *da = action_fifo_get(fifo);
  995. struct sk_buff *skb = da->skb;
  996. struct sw_flow_key *key = &da->pkt_key;
  997. const struct nlattr *actions = da->actions;
  998. if (actions)
  999. do_execute_actions(dp, skb, key, actions,
  1000. nla_len(actions));
  1001. else
  1002. ovs_dp_process_packet(skb, key);
  1003. } while (!action_fifo_is_empty(fifo));
  1004. /* Reset FIFO for the next packet. */
  1005. action_fifo_init(fifo);
  1006. }
  1007. /* Execute a list of actions against 'skb'. */
  1008. int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
  1009. const struct sw_flow_actions *acts,
  1010. struct sw_flow_key *key)
  1011. {
  1012. int err, level;
  1013. level = __this_cpu_inc_return(exec_actions_level);
  1014. if (unlikely(level > OVS_RECURSION_LIMIT)) {
  1015. net_crit_ratelimited("ovs: recursion limit reached on datapath %s, probable configuration error\n",
  1016. ovs_dp_name(dp));
  1017. kfree_skb(skb);
  1018. err = -ENETDOWN;
  1019. goto out;
  1020. }
  1021. OVS_CB(skb)->acts_origlen = acts->orig_len;
  1022. err = do_execute_actions(dp, skb, key,
  1023. acts->actions, acts->actions_len);
  1024. if (level == 1)
  1025. process_deferred_actions(dp);
  1026. out:
  1027. __this_cpu_dec(exec_actions_level);
  1028. return err;
  1029. }
  1030. int action_fifos_init(void)
  1031. {
  1032. action_fifos = alloc_percpu(struct action_fifo);
  1033. if (!action_fifos)
  1034. return -ENOMEM;
  1035. recirc_keys = alloc_percpu(struct recirc_keys);
  1036. if (!recirc_keys) {
  1037. free_percpu(action_fifos);
  1038. return -ENOMEM;
  1039. }
  1040. return 0;
  1041. }
  1042. void action_fifos_exit(void)
  1043. {
  1044. free_percpu(action_fifos);
  1045. free_percpu(recirc_keys);
  1046. }