mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
In case the 53 UDP port is not an option to bind then we hijack the DNS traffic with eBPF, and we forward the traffic to the listener on a custom port. With this implementation, we should be able to listen to DNS queries on any address and still set the local host system to send queries to the custom address on port 53. Because we tried to attach multiple XDP programs to the same interface, I did a refactor in the WG traffic forward code also.
42 lines
826 B
Go
42 lines
826 B
Go
package ebpf
|
|
|
|
import log "github.com/sirupsen/logrus"
|
|
|
|
const (
|
|
mapKeyProxyPort uint32 = 0
|
|
mapKeyWgPort uint32 = 1
|
|
)
|
|
|
|
func (tf *GeneralManager) LoadWgProxy(proxyPort, wgPort int) error {
|
|
log.Debugf("load ebpf WG proxy")
|
|
tf.lock.Lock()
|
|
defer tf.lock.Unlock()
|
|
|
|
err := tf.loadXdp()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = tf.bpfObjs.NbWgProxySettingsMap.Put(mapKeyProxyPort, uint16(proxyPort))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = tf.bpfObjs.NbWgProxySettingsMap.Put(mapKeyWgPort, uint16(wgPort))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
tf.setFeatureFlag(featureFlagWGProxy)
|
|
err = tf.bpfObjs.NbFeatures.Put(mapKeyFeatures, tf.featureFlags)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (tf *GeneralManager) FreeWGProxy() error {
|
|
log.Debugf("free ebpf WG proxy")
|
|
return tf.unsetFeatureFlag(featureFlagWGProxy)
|
|
}
|