Debian Codegraph @

tests/profinet_veth/veth.sh

raw symbols SCIP
1 #!/bin/bash
2 #
3 # Copyright (C) 2025 Linutronix GmbH
4 # Author Kurt Kanzenbach <[email protected]>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause
7 #
8 # Create virtual network interfaces move them into containers and bridge them together.
9 #
10
11 set -e
12
13 #
14 # Network for containers
15 #
16 ip link add veth0 type veth peer name veth0tb
17 ip link add veth1 type veth peer name veth1tb
18
19 #
20 # Setup MAC addresses.
21 #
22 HOSTNAME=$(hostname)
23 if [ "${HOSTNAME}" = "bpc1" ]; then
24 ifconfig veth0tb hw ether 5e:a7:0c:3f:e4:a9
25 ifconfig veth1tb hw ether d2:4c:c5:e2:f7:b7
26 else
27 ifconfig veth0tb hw ether 5e:a7:0c:3f:e4:aa
28 ifconfig veth1tb hw ether d2:4c:c5:e2:f7:b8
29 fi
30
31 #
32 # Setup veth up
33 #
34 ip link set veth0 up
35 ip link set veth1 up
36
37 #
38 # Move vethXtb to container network namespaces
39 #
40 NETNS1=$(lsns -t net | tail -n1 | awk '{ print $4 }')
41 NETNS2=$(lsns -t net | tail -n2 | head -n 1 | awk '{ print $4 }')
42 ip link set veth0tb netns ${NETNS1}
43 ip link set veth1tb netns ${NETNS2}
44
45 #
46 # Bridge together: virtual and physical NICs
47 #
48 ip link add br0 type bridge
49 ip link set veth0 master br0
50 ip link set veth1 master br0
51 ip link set enp3s0 master br0
52 ip link set br0 up
53
54 #
55 # Ignore iptable rules setup by docker
56 #
57 sysctl net.bridge.bridge-nf-call-iptables=0
58
59 #
60 # Configure VLANs on br0
61 #
62 ifconfig enp3s0.100 down
63 ip link delete enp3s0.100
64 ip link set dev br0 type bridge vlan_filtering 1
65 bridge vlan add dev enp3s0 vid 100
66 bridge vlan add dev veth0 vid 100
67 bridge vlan add dev veth1 vid 100
68 bridge vlan add dev enp3s0 vid 200
69 bridge vlan add dev veth0 vid 200
70 bridge vlan add dev veth1 vid 200
71
72 #
73 # Setup MAC addresses.
74 #
75 if [ "${HOSTNAME}" = "bpc1" ]; then
76 ifconfig br0 hw ether d6:96:12:ef:d6:77
77 else
78 ifconfig br0 hw ether d6:96:12:ef:d6:78
79 fi