6
24
Fork
You've already forked ifstate
13

Creating a pair of veth interfaces in different namespaces #34

Closed
opened 2024年01月04日 08:39:57 +01:00 by magic_rb · 5 comments
Contributor
Copy link

From what I managed to infer from the schema this config should work:

namespaces:test-ns:interfaces:- name:veth0link:kind:vethpeer:test-ns-veth0interfaces:- name:test-veth0link:kind:vethpeer:veth0peer_netns:test-ns

Though obviously peer_netns is not according to schema, therefore I'm not sure how to achieve what I want.

From what I managed to infer from the schema this config should work: ```yaml namespaces: test-ns: interfaces: - name: veth0 link: kind: veth peer: test-ns-veth0 interfaces: - name: test-veth0 link: kind: veth peer: veth0 peer_netns: test-ns ``` Though obviously `peer_netns` is not according to schema, therefore I'm not sure how to achieve what I want.
Author
Contributor
Copy link

I tried looking at the code whether I could implement this myself but I'm very lost honestly. I don't quite see where and how peer is even used. I found the quirk in veth.py but I have no clue how it fits into the rest of the code.

I tried looking at the code whether I could implement this myself but I'm very lost honestly. I don't quite see where and how `peer` is even used. I found the quirk in `veth.py` but I have no clue how it fits into the rest of the code.
Owner
Copy link

The implementation for veth is a bit older and I have to admit that it was not well tested with the new namespaces feature of IfState, yet.

(削除) Background: the netns handling for veth comes directly from pyroute2. (削除ここまで)

Sorry for the confusion: the master_netns option is not veth related at all, it is related to the master attribute (i.e. assign the veth to a bridge in another netns)

To fix:

  • extend schema with a peer_netns, this is almost the same as bind_netns for tunnel interfaces
  • register peer link creation in the LinkRegistry to prevent creating each peer individually
The implementation for veth is a bit older and I have to admit that it was not well tested with the new namespaces feature of IfState, yet. ~~Background: the netns handling for veth comes directly from pyroute2.~~ Sorry for the confusion: the `master_netns` option is **not** veth related at all, it is related to the `master` attribute (i.e. assign the veth to a bridge in another netns) To fix: - extend schema with a `peer_netns`, this is almost the same as `bind_netns` for tunnel interfaces - register peer link creation in the `LinkRegistry` to prevent creating each peer individually
liske added this to the 1.11.5 milestone 2024年01月04日 18:12:19 +01:00
Owner
Copy link

With the patch you can use the peer_netns attribute to span a veth between different netns:

interfaces:- name:test-veth1link:kind:vethpeer:test-veth0peer_netns:tenant1namespaces:tenant1:interfaces:- name:test-veth0link:kind:vethpeer:test-veth1peer_netns:null

(if peer_netns is not set it defaults to the netns of the interface)

With the patch you can use the `peer_netns` attribute to span a veth between different netns: ```yaml interfaces: - name: test-veth1 link: kind: veth peer: test-veth0 peer_netns: tenant1 namespaces: tenant1: interfaces: - name: test-veth0 link: kind: veth peer: test-veth1 peer_netns: null ``` (if `peer_netns` is *not* set it defaults to the netns of the interface)
Author
Contributor
Copy link
interfaces:[]# - name: test-veth1# link:# kind: veth# peer: test-veth0# peer_netns: tenant1namespaces:tenant1:interfaces:[]# - name: test-veth0# link:# kind: veth# peer: test-veth1# peer_netns: null

The config above leads to the output below (before i ran ifstate with the one you sent), it seems like it tries to delete one of the peers twice.

configure network namespaces...
 tenant1 ok
cleanup orphan interfaces...
 test-veth1 del
 test-veth0[netns=tenant1] del
removing link test-veth0 failed: No such device
configure interfaces...
 lo
 link ok
 addresses = 127.0.0.1/8
 addresses = ::1/128
 lo[netns=tenant1]
 link ok
 addresses = 127.0.0.1/8
 addresses = ::1/128
configure routing...
```yaml interfaces: [] # - name: test-veth1 # link: # kind: veth # peer: test-veth0 # peer_netns: tenant1 namespaces: tenant1: interfaces: [] # - name: test-veth0 # link: # kind: veth # peer: test-veth1 # peer_netns: null ``` The config above leads to the output below (before i ran `ifstate` with the one you sent), it seems like it tries to delete one of the peers twice. ``` configure network namespaces... tenant1 ok cleanup orphan interfaces... test-veth1 del test-veth0[netns=tenant1] del removing link test-veth0 failed: No such device configure interfaces... lo link ok addresses = 127.0.0.1/8 addresses = ::1/128 lo[netns=tenant1] link ok addresses = 127.0.0.1/8 addresses = ::1/128 configure routing... ```
Owner
Copy link

IfState removes both peers on after the other, but the kernel deletes the second peer when the first one is removed. This is mainly a cosmetic bug.

IfState removes both peers on after the other, but the kernel deletes the second peer when the first one is removed. This is mainly a cosmetic bug.
Sign in to join this conversation.
No Branch/Tag specified
main
move-paths-into-module
feature-libifstate-rs
ifstate-2.4
pages
ifstate-2.1
ifstate-2.3
ifstate-2.0
ifstate-2.2
ifstate-1.x
2.4.1
2.4.0
2.3.0
2.3.0-pre6
2.2.6
2.3.0-pre5
2.3.0-pre4
2.3.0-pre3
2.3.0-pre2
2.3.0-pre1
2.2.5
2.3.0-pre0
2.2.4
2.2.4-pre2
2.2.4-pre1
2.2.4-pre0
2.2.3
2.2.2
2.2.1
2.2.0
2.1.0
1.13.9
2.0.2
2.0.1
1.13.8
2.0.0
2.0.0rc6
2.0.0rc5
2.0.0rc4
2.0.0rc3
2.0.0rc2
2.0.0rc1
1.13.7
1.13.6
1.13.5
1.13.4
1.13.3
1.13.2
1.13.1
1.13.0
1.12.0
1.11.9
1.11.8
1.11.7
1.11.6
1.11.5
1.11.4
1.11.3
1.11.2
1.11.1
1.11.0
1.10.1
1.10.0
1.9.0
1.8.5
1.8.4
1.8.3
1.8.2
1.8.1
1.8.0
1.7.0
1.6.1
1.6.0
1.5.8
1.5.7
1.5.6
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.1
1.2.0
1.1.0
1.0.0
0.9.0
0.8.1
0.8.0
0.7.3
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.1
0.5
0.4
0.3
0.2
Labels
Clear labels
bug
Something isn't working
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
more info
Further details are required, the problem may not yet be reproducible, yet
question
Further information is requested
TBD
To be discussed
wontfix
This will not be worked on
AI slop
Burning out
bug
Something is not working
contribution welcome
Contributions are very welcome, get started here
duplicate
This issue or pull request already exists
enhancement
New feature
good first issue
Interested in contributing? Get started here.
help wanted
Need some help
invalid
Something is wrong
question
More information is needed
upstream
Related to an upstream repository, already reported there
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
routerkit/ifstate#34
Reference in a new issue
routerkit/ifstate
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?