conlink 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -146,6 +146,7 @@ The following table describes the link properties:
146
146
  | mode | 5 | string | | virt intf mode |
147
147
  | vlanid | vlan | number | | VLAN ID |
148
148
  | forward | veth | strings 6 8 | | forward conlink ports 7 |
149
+ | ethtool | veth | strings 8 | | ethtool settings |
149
150
 
150
151
  - 1 - veth, dummy, vlan, ipvlan, macvlan, ipvtap, macvtap
151
152
  - 2 - defaults to outer compose service
@@ -188,6 +189,12 @@ For publicly publishing a port, the conlink container needs to be on
188
189
  a docker network and the `conlink_port` should match the target port
189
190
  of a docker published port (for the conlink container).
190
191
 
192
+ For the `ethtool` property, refer to the `ethtool` man page. The
193
+ syntax for each ethtool setting is basically the ethtool command line
194
+ arguments without the "devname. So the equivalent of the ethtool
195
+ command `ethtool --offload eth0 rx off` would be link configuration
196
+ `{dev: eth0, ethtool: ["--offload rx off"], ...}`.
197
+
191
198
  ### Bridges
192
199
 
193
200
  The bridge settings currently only support the "mode" setting. If
@@ -29,6 +29,7 @@ services:
29
29
  mac: 00:0a:0b:0c:0d:01
30
30
  mtu: 4111
31
31
  netem: "rate 10mbit delay 40ms"
32
+ ethtool: "--offload rx off"
32
33
  - bridge: s2
33
34
  ip: 100.0.1.1/16
34
35
  dev: eth1
package/link-add.sh CHANGED
@@ -42,7 +42,10 @@ usage () {
42
42
  echo >&2 " --remote REMOTE - Remote address for geneve/vxlan types"
43
43
  echo >&2 " --vni VNI - Virtual Network Identifier for geneve/vxlan types"
44
44
  echo >&2 ""
45
- echo >&2 " --netem NETEM - tc qdisc netem OPTIONS (man 8 netem) (can repeat)"
45
+ echo >&2 " --netem NETEM - tc qdisc netem OPTIONS (can repeat)"
46
+ echo >&2 " (man 8 netem)"
47
+ echo >&2 " --ethtool 'ARG OPTS' - ethtool ARG INTF0 OPTS (can repeat)"
48
+ echo >&2 " (man 8 ethtool)"
46
49
  echo >&2 " --nat TARGET - Stateless NAT traffic to/from TARGET"
47
50
  echo >&2 " (in primary/PID0 netns)"
48
51
  echo >&2 ""
@@ -58,8 +61,8 @@ setup_if() {
58
61
  local IF=$1 NS=$2 MAC=$3 IP=$4 MTU=$5 ROUTES=$6 routes=
59
62
  echo >&2 "ROUTES: ${ROUTES}"
60
63
  while read rt; do
61
- [ "${rt}" ] && routes="${routes}\nroute add ${rt} dev ${IF}"
62
- done < <(echo -e "${ROUTES}")
64
+ routes="${routes}route add ${rt} dev ${IF}\n"
65
+ done < <(echo -en "${ROUTES}")
63
66
 
64
67
  info "Setting ${IP:+IP ${IP}, }${MAC:+MAC ${MAC}, }${MTU:+MTU ${MTU}, }${ROUTES:+ROUTES '${ROUTES//$'\n'/,}', }up state"
65
68
  ip -netns ${NS} --force -b - <<EOF
@@ -67,7 +70,7 @@ setup_if() {
67
70
  ${MAC:+link set dev ${IF} address ${MAC}}
68
71
  ${MTU:+link set dev ${IF} mtu ${MTU}}
69
72
  link set dev ${IF} up
70
- $(echo -e "${routes}")
73
+ $(echo -en "${routes}")
71
74
  EOF
72
75
  }
73
76
 
@@ -82,7 +85,7 @@ IPTABLES() {
82
85
  VERBOSE=${VERBOSE:-}
83
86
  PID1=${PID1:-<SELF>} IF1=${IF1:-eth0}
84
87
  IP0= IP1= MAC0= MAC1= ROUTES0= ROUTES1= MTU=
85
- MODE= VLANID= REMOTE= VNI= NETEM= NAT=
88
+ MODE= VLANID= REMOTE= VNI= NETEM= NAT= ETHTOOL=
86
89
  positional=
87
90
  while [ "${*}" ]; do
88
91
  param=$1; OPTARG=$2
@@ -94,10 +97,10 @@ while [ "${*}" ]; do
94
97
  --ip1) IP1="${OPTARG}"; shift ;;
95
98
  --mac|--mac0) MAC0="${OPTARG}"; shift ;;
96
99
  --mac1) MAC1="${OPTARG}"; shift ;;
97
- --route|--route0) ROUTES0="${ROUTES0}\n${OPTARG}"; shift ;;
98
- --route1) ROUTES1="${ROUTES1}\n${OPTARG}"; shift ;;
100
+ --route|--route0) ROUTES0="${ROUTES0}${OPTARG}\n"; shift ;;
101
+ --route1) ROUTES1="${ROUTES1}${OPTARG}\n"; shift ;;
99
102
  --mtu) MTU="${OPTARG}"; shift ;;
100
-
103
+ --ethtool) ETHTOOL="${ETHTOOL}${OPTARG}\n"; shift ;;
101
104
  --mode) MODE="${OPTARG}"; shift ;;
102
105
  --vlanid) VLANID="${OPTARG}"; shift ;;
103
106
 
@@ -111,8 +114,6 @@ while [ "${*}" ]; do
111
114
  esac
112
115
  shift
113
116
  done
114
- ROUTES0="${ROUTES0#\\n}"
115
- ROUTES1="${ROUTES1#\\n}"
116
117
  set -- ${positional}
117
118
  TYPE=$1 PID0=$2 IF0=$3
118
119
 
@@ -195,6 +196,11 @@ if [ "${NETEM}" ]; then
195
196
  tc -netns ${NS0} qdisc add dev ${IF0} root netem ${NETEM}
196
197
  fi
197
198
 
199
+ while read arg opts; do
200
+ info "Applying ethtool ${arg} ${IF0} ${opts} (in ${NS0})"
201
+ ip netns exec ${NS0} ethtool ${arg} ${IF0} ${opts}
202
+ done < <(echo -en "${ETHTOOL}")
203
+
198
204
  if [ "${NAT}" ]; then
199
205
  info "Adding NAT rule to ${NAT}"
200
206
  IPTABLES ${NS0} PREROUTING -t nat -i ${IF0} -j DNAT --to-destination ${NAT}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conlink",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "conlink - Declarative Low-Level Networking for Containers",
5
5
  "repository": "https://github.com/LonoCloud/conlink",
6
6
  "license": "SEE LICENSE IN LICENSE",
package/schema.yaml CHANGED
@@ -53,6 +53,9 @@ properties:
53
53
  netem:
54
54
  oneOf: [{type: string},
55
55
  {type: array, items: {type: string}}]
56
+ ethtool:
57
+ oneOf: [{type: string},
58
+ {type: array, items: {type: string}}]
56
59
 
57
60
  bridges:
58
61
  type: array
@@ -32,6 +32,8 @@ General Options:
32
32
  [default: auto] [env: CONLINK_BRIDGE_MODE]
33
33
  --default-mtu MTU Default link MTU (for non *vlan types)
34
34
  [default: 65535]
35
+ --keep-veth-offload Do not add '--offload tx off' as the first
36
+ ethtool setting for container veth interfaces
35
37
  --network-file NETWORK-FILE... Network config file
36
38
  --compose-file COMPOSE-FILE... Docker compose file with network config
37
39
  --compose-project NAME Docker compose project name for resolving
@@ -57,7 +59,8 @@ General Options:
57
59
  " --system-id=random --no-mlockall --delete-bridges"))
58
60
 
59
61
  (def VLAN-TYPES #{:vlan :macvlan :macvtap :ipvlan :ipvtap})
60
- (def LINK-ADD-OPTS [:ip :mac :route :mtu :nat :netem :mode :vlanid :remote :vni])
62
+ (def LINK-ADD-OPTS [:ip :mac :route :mtu :nat :netem :ethtool
63
+ :mode :vlanid :remote :vni])
61
64
  (def INTF-MAX-LEN 15)
62
65
  (def DOCKER-INTF "DOCKER-ETH0")
63
66
 
@@ -112,9 +115,9 @@ General Options:
112
115
  - mac: random MAC starting with first octet of 'c2'
113
116
  - mtu: --default-mtu (for non *vlan type)
114
117
  - base: :conlink for veth type, :host for *vlan types, :local otherwise"
115
- [{:as link :keys [type base bridge ip route forward netem]} bridges opts]
118
+ [{:as link :keys [type bridge ip route forward netem ethtool]} bridges opts]
116
119
  (let [{:keys [docker-eth0? docker-eth0-address]} @ctx
117
- {:keys [default-mtu]} opts
120
+ {:keys [default-mtu keep-veth-offload]} opts
118
121
  type (keyword (or type "veth"))
119
122
  dev (get link :dev "eth0")
120
123
  mac (get link :mac (random-mac))
@@ -126,12 +129,17 @@ General Options:
126
129
  route (if (string? route) [route] route)
127
130
  forward (if (string? forward) [forward] forward)
128
131
  netem (if (string? netem) [netem] netem)
132
+ ethtool-pre (if (and (= :veth type) (not keep-veth-offload))
133
+ ["--offload tx off"]
134
+ [])
135
+ ethtool (into ethtool-pre (if (string? ethtool) [ethtool] ethtool))
129
136
  link (merge
130
137
  link
131
138
  {:type type
132
139
  :dev dev
133
140
  :base base
134
- :mac mac}
141
+ :mac mac
142
+ :ethtool ethtool}
135
143
  (when bridge
136
144
  {:bridge bridge})
137
145
  (when (not (VLAN-TYPES type))
@@ -201,21 +209,21 @@ General Options:
201
209
  bridge-map
202
210
  (keep :bridge links))
203
211
  ;; Enrich each bridge
204
- bridges (reduce (fn [bs [k v]]
205
- (assoc bs k (enrich-bridge v opts)))
206
- {} all-bridges)
207
- ;; Restructure links into map to merge and enrich.
208
- ;; Merge key is server/container + dev
212
+ enriched-bridges (reduce (fn [bs [k v]]
213
+ (assoc bs k (enrich-bridge v opts)))
214
+ {} all-bridges)
215
+ ;; Restructure links into a map to merge
209
216
  link-map (reduce (fn [ls link]
210
- (let [elink (enrich-link link bridges opts)
211
- lid (str (or (:service link)
217
+ ;; Merge key is server/container + dev
218
+ (let [lid (str (or (:service link)
212
219
  (:container link))
213
- ":" (:dev elink))
214
- mlink (deep-merge (get ls lid) elink)]
215
- (assoc ls lid mlink)))
220
+ ":" (get link :dev "eth0"))]
221
+ (update ls lid deep-merge link)))
216
222
  {} links)
223
+ enriched-links (map #(enrich-link % enriched-bridges opts)
224
+ (vals link-map))
217
225
 
218
- cfg {:bridges bridges
226
+ cfg {:bridges enriched-bridges
219
227
  :tunnels tunnels
220
228
  :containers {}
221
229
  :services {}}
@@ -223,7 +231,7 @@ General Options:
223
231
  (cond-> cfg
224
232
  container (update-in [:containers container kind] conjv x)
225
233
  service (update-in [:services service kind] conjv x)))
226
- cfg (reduce (partial rfn :links) cfg (vals link-map))
234
+ cfg (reduce (partial rfn :links) cfg enriched-links)
227
235
  cfg (reduce (partial rfn :commands) cfg commands)]
228
236
  cfg))
229
237