Skip to content

Commit

Permalink
fix: support to bind dae to wg lan (and other tun) (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 authored Jul 16, 2023
1 parent ef6dc5d commit b34b5ac
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 124 deletions.
5 changes: 5 additions & 0 deletions common/consts/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ const (
LanWanFlag_IsLan
LanWanFlag_NotApplicable
)

const (
LinkType_None uint32 = iota
LinkType_Ethernet
)
1 change: 1 addition & 0 deletions control/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func NewControlPlane(
// Add clsact qdisc
for _, ifname := range common.Deduplicate(append(append([]string{}, global.LanInterface...), global.WanInterface...)) {
_ = core.addQdisc(ifname)
_ = core.mapLinkType(ifname)
}
// Bind to LAN
if len(global.LanInterface) > 0 {
Expand Down
16 changes: 16 additions & 0 deletions control/control_plane_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ func getIfParamsFromLink(link netlink.Link) (ifParams bpfIfParams, err error) {
return ifParams, nil
}

func (c *controlPlaneCore) mapLinkType(ifname string) error {
link, err := netlink.LinkByName(ifname)
if err != nil {
return err
}
linkType := uint32(0xffff)
switch link.Attrs().EncapType {
case "none":
linkType = consts.LinkType_None
case "ether":
linkType = consts.LinkType_Ethernet
default:
}
return c.bpf.bpfMaps.LinktypeMap.Update(uint32(link.Attrs().Index), linkType, ebpf.UpdateAny)
}

func (c *controlPlaneCore) addQdisc(ifname string) error {
link, err := netlink.LinkByName(ifname)
if err != nil {
Expand Down
Loading

0 comments on commit b34b5ac

Please sign in to comment.