X Tutup
Skip to content

Commit af94bb2

Browse files
committed
shared: Introduce bridge util
1 parent 12ef8fb commit af94bb2

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/shared/bridge-util.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: LGPL-2.1+ */
2+
3+
#include "bridge-util.h"
4+
#include "string-table.h"
5+
6+
static const char* const bridge_state_table[_NETDEV_BRIDGE_STATE_MAX] = {
7+
[NETDEV_BRIDGE_STATE_DISABLED] = "disabled",
8+
[NETDEV_BRIDGE_STATE_LISTENING] = "listening",
9+
[NETDEV_BRIDGE_STATE_LEARNING] = "learning",
10+
[NETDEV_BRIDGE_STATE_FORWARDING] = "forwading",
11+
};
12+
13+
DEFINE_STRING_TABLE_LOOKUP(bridge_state, BridgeState);

src/shared/bridge-util.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: LGPL-2.1+ */
2+
#pragma once
3+
4+
#include <netinet/in.h>
5+
#include <linux/if_bridge.h>
6+
7+
#include "conf-parser.h"
8+
9+
typedef enum BridgeState {
10+
NETDEV_BRIDGE_STATE_DISABLED = BR_STATE_DISABLED,
11+
NETDEV_BRIDGE_STATE_LISTENING = BR_STATE_LISTENING,
12+
NETDEV_BRIDGE_STATE_LEARNING = BR_STATE_LEARNING,
13+
NETDEV_BRIDGE_STATE_FORWARDING = BR_STATE_FORWARDING,
14+
NETDEV_BRIDGE_STATE_BLOCKING = BR_STATE_BLOCKING,
15+
_NETDEV_BRIDGE_STATE_MAX,
16+
_NETDEV_BRIDGE_STATE_INVALID = -1,
17+
} BridgeState;
18+
19+
const char *bridge_state_to_string(BridgeState d) _const_;
20+
BridgeState bridge_state_from_string(const char *d) _pure_;

src/shared/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ shared_sources = files('''
2121
bootspec.h
2222
bpf-program.c
2323
bpf-program.h
24+
bridge-util.c
25+
bridge-util.h
2426
bus-unit-procs.c
2527
bus-unit-procs.h
2628
bus-unit-util.c

0 commit comments

Comments
 (0)
X Tutup