16 #include <odp/helper/odph_api.h>
18 #include <odp_ipsec_fwd_db.h>
23 void init_fwd_db(
void)
33 ODPH_ERR(
"Error: shared mem reserve failed.\n");
40 ODPH_ERR(
"Error: shared mem alloc failed.\n");
43 memset(fwd_db, 0,
sizeof(*fwd_db));
46 int create_fwd_db_entry(
char *input,
char **if_names,
int if_count)
48 int pos = 0, i, match = 0;
53 fwd_db_entry_t *entry = &fwd_db->array[fwd_db->index];
56 if (MAX_DB <= fwd_db->index)
60 local = malloc(strlen(input) + 1);
70 while (NULL != (token = strtok_r(str,
",", &save))) {
76 parse_ipv4_string(token,
81 odph_strcpy(entry->oif, token, OIF_LEN);
82 for (i = 0; i < if_count; i++) {
83 if (!strcmp(if_names[i], entry->oif)) {
89 printf(
"ERROR: interface name not correct for route\n");
95 parse_mac_string(token, entry->dst_mac);
98 printf(
"ERROR: extra token \"%s\" at position %d\n",
109 printf(
"ERROR: \"%s\" contains %d tokens, expected 3\n",
118 entry->next = fwd_db->list;
119 fwd_db->list = entry;
128 fwd_db_entry_t *entry;
131 for (entry = fwd_db->list; NULL != entry; entry = entry->next) {
132 if (strcmp(intf, entry->oif))
135 entry->pktio = pktio;
136 entry->pktout = pktout;
137 memcpy(entry->src_mac, mac, ODPH_ETHADDR_LEN);
141 void dump_fwd_db_entry(fwd_db_entry_t *entry)
143 char subnet_str[MAX_STRING];
144 char mac_str[MAX_STRING];
146 printf(
" %s %s %s\n",
147 ipv4_subnet_str(subnet_str, &entry->subnet),
149 mac_addr_str(mac_str, entry->dst_mac));
152 void dump_fwd_db(
void)
154 fwd_db_entry_t *entry;
160 for (entry = fwd_db->list; NULL != entry; entry = entry->next)
161 dump_fwd_db_entry(entry);
164 fwd_db_entry_t *find_fwd_db_entry(uint32_t dst_ip)
166 fwd_db_entry_t *entry;
168 for (entry = fwd_db->list; NULL != entry; entry = entry->next)
169 if (entry->subnet.addr == (dst_ip & entry->subnet.mask))
#define ODP_SHM_INVALID
Invalid shared memory block.
void * odp_shm_addr(odp_shm_t shm)
Shared memory block address.
odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags)
Reserve a contiguous block of shared memory.