-
Notifications
You must be signed in to change notification settings - Fork 2
/
mpis-table.c
60 lines (50 loc) · 1.47 KB
/
mpis-table.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <errno.h>
#include "mpis-table.h"
#include "log.h"
#include "mpis.h"
static mpis_table table[MAX_ENTRIES];
static int retval;
static size_t n_entries;
void new_table() {
retval = 0;
n_entries = 0;
}
void end_table() {
// nothing to do for now
}
mpis_table *get_table(size_t *table_sz) {
*table_sz = n_entries;
return table;
}
void add_entry(uint8_t target_type, const char *ifname, uint32_t selector, uint32_t target, uint8_t cidr, uint32_t target_data, uint8_t flags) {
mpis_table *current_entry = &table[n_entries++];
memset(current_entry, 0, sizeof(mpis_table));
current_entry->iif = if_nametoindex(ifname);
if (current_entry->iif == 0) {
log_error("invalid interface name '%s': %s\n", ifname, strerror(errno));
retval = -1;
return;
}
if ((cidr > 32 || cidr < 16) && !(flags & TFLAG_OVERRIDE_FRAG)) {
log_error("invalid prefix length - must be between 16 and 32 if not using override-frag\n");
retval = -1;
return;
}
current_entry->selector = selector;
current_entry->cidr = cidr;
current_entry->mask = ~((1 << (32 - cidr)) - 1);
current_entry->target_type = target_type;
current_entry->target = target;
current_entry->target_data = target_data;
current_entry->target_flags = flags;
}
void store_retval(int val) {
retval = val;
}
int get_retval() {
return retval;
}