2 // Copyright (c) 2010-2020 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef _PACKET_UTILS_H_
17 #define _PACKET_UTILS_H_
19 #include <rte_cycles.h>
21 #include "prox_compat.h"
24 #include "prox_malloc.h"
29 #define FLAG_DST_MAC_KNOWN 1
30 #define MAX_ARP_ENTRIES 65536
32 #define IP4(x) x & 0xff, (x >> 8) & 0xff, (x >> 16) & 0xff, x >> 24 // From Network (BE)
39 #define DEFAULT_ARP_TIMEOUT (1000 * 3600 * 24 * 15) // ~15 days = disabled by default
40 #define DEFAULT_ARP_UPDATE_TIME (1000) // 1 second
46 uint64_t arp_ndp_retransmit_timeout;
47 uint64_t reachable_timeout;
50 prox_rte_ether_addr mac;
54 struct rte_ring *ctrl_plane_ring;
55 struct task_base *tmaster;
59 uint8_t reachable_port_id;
63 prox_next_hop_index_type nb_gws;
64 uint32_t arp_ndp_retransmit_timeout;
65 uint32_t reachable_timeout;
67 struct arp_table optimized_arp_table[4];
68 struct rte_hash *ip_hash;
69 struct rte_hash *ip6_hash;
70 struct arp_table *arp_table;
71 struct rte_lpm *ipv4_lpm;
72 struct arp_table *next_hops;
73 struct rte_mempool *arp_nd_pool;
74 struct ipv6_addr local_ipv6;
75 struct ipv6_addr global_ipv6;
76 uint8_t prefix_printed;
79 void task_init_l3(struct task_base *tbase, struct task_args *targ);
80 void task_start_l3(struct task_base *tbase, struct task_args *targ);
81 int write_dst_mac(struct task_base *tbase, struct rte_mbuf *mbuf, uint32_t *ip_dst, uint16_t *vlan, uint64_t **time, uint64_t tsc);
82 int write_ip6_dst_mac(struct task_base *tbase, struct rte_mbuf *mbuf, struct ipv6_addr *ip_dst, uint16_t *vlan, uint64_t tsc);
83 void task_set_gateway_ip(struct task_base *tbase, uint32_t ip);
84 void task_set_local_ip(struct task_base *tbase, uint32_t ip);
85 void handle_ctrl_plane_pkts(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts);
86 void send_unsollicited_neighbour_advertisement(struct task_base *tbase);
88 static inline void update_arp_ndp_retransmit_timeout(struct l3_base *l3, uint64_t *ptr, uint32_t base)
90 // randomize timers - from 0.5 to 1.5 * configured time
91 const uint64_t hz = rte_get_tsc_hz();
92 uint64_t tsc = rte_rdtsc();
93 uint64_t rand = 500 + (1000L * rand_r(&l3->seed)) / RAND_MAX;
94 *ptr = tsc + (base * rand / 1000) * hz / 1000;
96 static inline uint8_t get_port(struct rte_mbuf *mbuf)
101 #endif /* _PACKET_UTILS_H_ */