actions.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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. }