Merge pull request #20261 from pprindeville/strongswan-update-5.9.9
[feed/packages.git] / net / cni-protocol / files / cni.sh
1 #!/bin/sh
2
3 [ -n "$INCLUDE_ONLY" ] || {
4 . /lib/functions.sh
5 . ../netifd-proto.sh
6 init_proto "$@"
7 }
8
9 proto_cni_init_config() {
10 no_device=0
11 available=0
12 no_proto_task=1
13 teardown_on_l3_link_down=1
14
15 proto_config_add_string "device:device"
16 }
17
18 proto_cni_setup() {
19
20 local cfg="$1"
21 local device ipaddr netmask broadcast route routemask routesrc
22
23 json_get_var device device
24
25 ipaddr=$(ip -4 -o a show "$device" | awk '{ print $4 }' | cut -d '/' -f1)
26 netmask=$(ip -4 -o a show "$device" | awk '{ print $4 }' | cut -d '/' -f2)
27 broadcast=$(ip -4 -o a show "$device" | awk '{ print $6 }')
28 route=$(ip -4 -o r show dev "$device" | awk '{ print $1 }' | cut -d '/' -f1)
29 routemask=$(ip -4 -o r show dev "$device" | awk '{ print $1 }' | cut -d '/' -f2)
30 routesrc=$(ip -4 -o r show dev "$device" | awk '{ print $7 }')
31
32 [ -z "$ipaddr" ] && {
33 echo "cni network $cfg does not have ip address"
34 proto_notify_error "$cfg" NO_IPADDRESS
35 return 1
36 }
37
38 proto_init_update "$device" 1
39 [ -n "$ipaddr" ] && proto_add_ipv4_address "$ipaddr" "$netmask" "$broadcast" ""
40 [ -n "$route" ] && proto_add_ipv4_route "$route" "$routemask" "" "$routesrc" ""
41 proto_send_update "$cfg"
42 }
43
44 proto_cni_teardown() {
45 local cfg="$1"
46 #proto_set_available "$cfg" 0
47 return 0
48 }
49
50 [ -n "$INCLUDE_ONLY" ] || {
51 add_protocol cni
52 }