-
Notifications
You must be signed in to change notification settings - Fork 5
/
bridger.h
66 lines (51 loc) · 1.46 KB
/
bridger.h
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
61
62
63
64
65
66
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2022 Felix Fietkau <[email protected]>
*/
#ifndef __BRIDGER_H
#define __BRIDGER_H
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#include <libubox/uloop.h>
#include <libubox/list.h>
#include <libubox/avl.h>
#include <libubox/utils.h>
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
#include "bridger-bpf.h"
#include "device.h"
#include "flow.h"
#include "fdb.h"
#include "bpf.h"
#include "nl.h"
#include "ubus.h"
#define D(format, ...) \
do { \
if (debug_level) \
fprintf(stderr, "%s(%d) " format, __func__, __LINE__, ##__VA_ARGS__); \
} while(0)
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
#define BRIDGER_PROG_PATH "/lib/bpf/bridger-bpf.o"
#define BRIDGER_PIN_PATH "/sys/fs/bpf/bridger"
#define BRIDGER_DATA_PATH "/sys/fs/bpf/bridger_data"
#define BRIDGER_EWMA_SHIFT 8
#define BRIDGER_PRIO_BPF 0xbb00
#define BRIDGER_PRIO_OFFLOAD_8021Q 0xbb01
#define BRIDGER_PRIO_OFFLOAD_8021AD 0xbb02
#define BRIDGER_PRIO_OFFLOAD_UNTAG 0xbb03
#define BRIDGER_PRIO_OFFLOAD_START BRIDGER_PRIO_OFFLOAD_8021Q
#define BRIDGER_PRIO_OFFLOAD_END BRIDGER_PRIO_OFFLOAD_UNTAG
extern int debug_level;
extern bool bridge_local_rx;
static inline void bridger_ewma(uint64_t *avg, uint32_t val)
{
if (*avg)
*avg = (*avg * 3) / 4 + ((uint64_t)val << BRIDGER_EWMA_SHIFT) / 4;
else
*avg = (uint64_t)val << BRIDGER_EWMA_SHIFT;
}
const char *format_macaddr(const uint8_t *mac);
#endif