Support packets in flight
[samplevnf.git] / VNFs / DPPD-PROX / prox_lua_types.h
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef _PROX_LUA_TYPES_H_
18 #define _PROX_LUA_TYPES_H_
19
20 #include <inttypes.h>
21 #include <rte_ether.h>
22 #include <rte_hash.h>
23
24 #include "prox_compat.h"
25 #include "ip6_addr.h"
26
27 struct lua_State;
28 struct ip4_subnet;
29 struct ip6_subnet;
30 struct next_hop;
31 struct rte_lpm;
32 struct rte_lpm6;
33 struct next_hop6;
34 struct rte_acl_ctx;
35 struct qinq_gre_map;
36
37 #define MAX_HOP_INDEX  128
38 enum l4gen_peer {PEER_SERVER, PEER_CLIENT};
39
40 static const char *l4gen_peer_to_str(enum l4gen_peer peer)
41 {
42         return peer == PEER_SERVER? "server" : "client";
43 }
44
45 struct peer_data {
46         uint8_t *hdr;
47         uint32_t hdr_len;
48         uint8_t *content;
49 };
50
51 struct peer_action {
52         enum l4gen_peer   peer;
53         uint32_t          beg;
54         uint32_t          len;
55 };
56
57 struct lpm4 {
58         uint32_t n_free_rules;
59         uint32_t n_used_rules;
60         struct next_hop *next_hops;
61         struct rte_lpm *rte_lpm;
62 };
63
64 struct lpm6 {
65         struct rte_lpm6 *rte_lpm6;
66         struct next_hop6 *next_hops;
67         uint32_t n_free_rules;
68         uint32_t n_used_rules;
69 };
70
71 struct ipv6_tun_binding_entry {
72         struct ipv6_addr        endpoint_addr;  // IPv6 local addr
73         prox_rte_ether_addr       next_hop_mac;   // mac addr of next hop towards lwB4
74         uint32_t                public_ipv4;    // Public IPv4 address
75         uint16_t                public_port;    // Public base port (together with port mask, defines the Port Set)
76 } __attribute__((__packed__)) __attribute__((__aligned__(2)));
77
78 struct ipv6_tun_binding_table {
79         uint32_t                num_binding_entries;
80         struct ipv6_tun_binding_entry entry[0];
81 };
82
83 struct cpe_table_entry {
84         uint32_t port_idx;
85         uint32_t gre_id;
86         uint32_t svlan;
87         uint32_t cvlan;
88         uint32_t ip;
89         prox_rte_ether_addr eth_addr;
90         uint32_t user;
91 };
92
93 struct cpe_table_data {
94         uint32_t               n_entries;
95         struct cpe_table_entry entries[0];
96 };
97
98 struct val_mask {
99         uint32_t val;
100         uint32_t mask;
101 };
102
103 struct val_range {
104         uint32_t beg;
105         uint32_t end;
106 };
107
108 enum acl_action {ACL_NOT_SET, ACL_ALLOW, ACL_DROP, ACL_RATE_LIMIT};
109
110 const char *get_lua_to_errors(void);
111
112 enum lua_place {STACK, TABLE, GLOBAL};
113 int lua_getfrom(struct lua_State *L, enum lua_place from, const char *name);
114
115 int lua_to_port(struct lua_State *L, enum lua_place from, const char *name, uint16_t *port);
116 int lua_to_ip(struct lua_State *L, enum lua_place from, const char *name, uint32_t *ip);
117 int lua_to_ip6(struct lua_State *L, enum lua_place from, const char *name, uint8_t *ip);
118 int lua_to_mac(struct lua_State *L, enum lua_place from, const char *name, prox_rte_ether_addr *mac);
119 int lua_to_cidr(struct lua_State *L, enum lua_place from, const char *name, struct ip4_subnet *cidr);
120 int lua_to_cidr6(struct lua_State *L, enum lua_place from, const char *name, struct ip6_subnet *cidr);
121 int lua_to_int(struct lua_State *L, enum lua_place from, const char *name, uint32_t *val);
122 int lua_to_double(struct lua_State *L, enum lua_place from, const char *name, double *val);
123 int lua_to_string(struct lua_State *L, enum lua_place from, const char *name, char *dst, size_t size);
124 int lua_to_val_mask(struct lua_State *L, enum lua_place from, const char *name, struct val_mask *val_mask);
125 int lua_to_val_range(struct lua_State *L, enum lua_place from, const char *name, struct val_range *val_range);
126 int lua_to_action(struct lua_State *L, enum lua_place from, const char *name, enum acl_action *action);
127 int lua_to_dscp(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, uint8_t **dscp);
128 int lua_to_user_table(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, uint16_t **user_table);
129 int lua_to_lpm4(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct lpm4 **lpm);
130 int lua_to_routes4(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct lpm4 *lpm);
131 int lua_to_next_hop(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct next_hop **nh);
132 int lua_to_lpm6(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct lpm6 **lpm);
133 int lua_to_ip6_tun_binding(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct ipv6_tun_binding_table **data);
134 int lua_to_qinq_gre_map(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct qinq_gre_map **qinq_gre_map);
135 int lua_to_cpe_table_data(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct cpe_table_data **data);
136 int lua_to_rules(struct lua_State *L, enum lua_place from, const char *name, struct rte_acl_ctx *ctx, uint32_t* n_max_rules, int use_qinq, uint16_t qinq_tag);
137 int lua_to_routes4_entry(struct lua_State *L, enum lua_place from, const char *name, struct ip4_subnet *cidr, uint32_t *nh_idx);
138 int lua_to_next_hop6(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct next_hop6 **nh);
139 int lua_to_routes6(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct lpm6 *lpm);
140 int lua_to_tuples(struct lua_State *L, enum lua_place from, const char *name, uint8_t socket, struct rte_hash **lookup_hash, uint8_t **out_if);
141
142 #endif /* _PROX_LUA_TYPES_H_ */