Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR - support blacklisting of certain interfaces #366

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions api/loxinlp/nlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ type NlH struct {
LinkUpdateCh
NeighUpdateCh
RouteUpdateCh
IMap map[string]Intf
IMap map[string]Intf
BlackList string
BLRgx *regexp.Regexp
}

var hooks cmn.NetHookInterface
Expand Down Expand Up @@ -1198,6 +1200,12 @@ func DelRoute(route nlp.Route) int {

func LUWorkSingle(m nlp.LinkUpdate) int {
var ret int

filter := nNl.BLRgx.MatchString(m.Link.Attrs().Name)
if filter {
return -1
}

ret = ModLink(m.Link, m.Header.Type == syscall.RTM_NEWLINK)
return ret
}
Expand All @@ -1210,6 +1218,11 @@ func AUWorkSingle(m nlp.AddrUpdate) int {
return -1
}

filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
return -1
}

attrs := link.Attrs()
name := attrs.Name
if m.NewAddr {
Expand Down Expand Up @@ -1243,6 +1256,11 @@ func NUWorkSingle(m nlp.NeighUpdate) int {
return -1
}

filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
return -1
}

add := m.Type == syscall.RTM_NEWNEIGH

if add {
Expand All @@ -1257,6 +1275,17 @@ func NUWorkSingle(m nlp.NeighUpdate) int {
func RUWorkSingle(m nlp.RouteUpdate) int {
var ret int

link, err := nlp.LinkByIndex(m.LinkIndex)
if err != nil {
fmt.Println(err)
return -1
}

filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
return -1
}

if m.Type == syscall.RTM_NEWROUTE {
ret = AddRoute(m.Route)
} else {
Expand Down Expand Up @@ -1338,6 +1367,10 @@ func GetBridges() {
return
}
for _, link := range links {
filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
continue
}
switch link.(type) {
case *nlp.Bridge:
{
Expand All @@ -1360,8 +1393,13 @@ func NlpGet(ch chan bool) int {
}

for _, link := range links {
ret = ModLink(link, true)

filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
continue
}

ret = ModLink(link, true)
if ret == -1 {
continue
}
Expand Down Expand Up @@ -1488,7 +1526,7 @@ func LbSessionGet(done bool) int {
return 0
}

func NlpInit(bgpPeerMode bool) *NlH {
func NlpInit(bgpPeerMode bool, blackList string) *NlH {

nNl = new(NlH)

Expand All @@ -1506,6 +1544,8 @@ func NlpInit(bgpPeerMode bool) *NlH {
return nNl
}

nNl.BlackList = blackList
nNl.BLRgx = regexp.MustCompile(blackList)
nNl.FromAUCh = make(chan nlp.AddrUpdate, cmn.AuWorkqLen)
nNl.FromLUCh = make(chan nlp.LinkUpdate, cmn.LuWorkQLen)
nNl.FromNUCh = make(chan nlp.NeighUpdate, cmn.NuWorkQLen)
Expand Down
22 changes: 10 additions & 12 deletions cicd/k3s-flannel-incluster/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# vi: set ft=ruby :

workers = (ENV['WORKERS'] || "2").to_i
#box_name = (ENV['VAGRANT_BOX'] || "ubuntu/focal64")
box_name = (ENV['VAGRANT_BOX'] || "sysnet4admin/Ubuntu-k8s")
box_version = "0.7.1"
Vagrant.configure("2") do |config|
Expand All @@ -13,17 +12,16 @@ Vagrant.configure("2") do |config|
config.vbguest.auto_update = false
end

#config.vm.define "loxilb" do |loxilb|
# loxilb.vm.hostname = 'llb1'
#loxilb.vm.network "forwarded_port", guest: 55002, host: 5502, protocol: "tcp"
# loxilb.vm.network :private_network, ip: "192.168.80.9", :netmask => "255.255.255.0"
# loxilb.vm.network :private_network, ip: "192.168.90.9", :netmask => "255.255.255.0"
# loxilb.vm.provision :shell, :path => "loxilb.sh"
# loxilb.vm.provider :virtualbox do |vbox|
# vbox.customize ["modifyvm", :id, "--memory", 6000]
# vbox.customize ["modifyvm", :id, "--cpus", 4]
# end
#end
config.vm.define "host" do |host|
host.vm.hostname = 'host1'
host.vm.network :private_network, ip: "192.168.80.9", :netmask => "255.255.255.0"
host.vm.network :private_network, ip: "192.168.90.9", :netmask => "255.255.255.0"
host.vm.provision :shell, :path => "host.sh"
host.vm.provider :virtualbox do |vbox|
vbox.customize ["modifyvm", :id, "--memory", 2048]
vbox.customize ["modifyvm", :id, "--cpus", 1]
end
end

config.vm.define "master1" do |master|
master.vm.hostname = 'master1'
Expand Down
2 changes: 2 additions & 0 deletions cicd/k3s-flannel-incluster/host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sudo ip route add 123.123.123.0/24 via 192.168.90.10
echo "Host is up"
2 changes: 1 addition & 1 deletion cicd/k3s-flannel-incluster/loxilb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
containers:
- name: loxilb-app
image: "ghcr.io/loxilb-io/loxilb:latest"
command: [ "/root/loxilb-io/loxilb/loxilb", "--bgp", "--egr-hooks" ]
command: [ "/root/loxilb-io/loxilb/loxilb", "--bgp", "--egr-hooks", "--blacklist=cni[0-9a-z]|veth.|flannel." ]
ports:
- containerPort: 11111
- containerPort: 179
Expand Down
4 changes: 2 additions & 2 deletions cicd/k3s-flannel-incluster/master1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ echo $MASTER_IP > /vagrant/master-ip
cp /var/lib/rancher/k3s/server/node-token /vagrant/node-token
sed -i -e "s/127.0.0.1/${MASTER_IP}/g" /etc/rancher/k3s/k3s.yaml
cp /etc/rancher/k3s/k3s.yaml /vagrant/k3s.yaml
#sudo kubectl apply -f /vagrant/loxilb.yml
#sudo kubectl apply -f /vagrant/kube-loxilb.yml
sudo kubectl apply -f /vagrant/loxilb.yml
sudo kubectl apply -f /vagrant/kube-loxilb.yml
/vagrant/wait_ready.sh
1 change: 1 addition & 0 deletions cicd/k3s-flannel-incluster/rmconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vagrant destroy -f worker1
vagrant destroy -f worker2
vagrant destroy -f master1
vagrant destroy -f master2
vagrant destroy -f host
1 change: 1 addition & 0 deletions cicd/k3s-flannel-incluster/worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export NODE_TOKEN=$(cat /vagrant/node-token)
mkdir -p /etc/rancher/k3s
cp -f /vagrant/k3s.yaml /etc/rancher/k3s/k3s.yaml
curl -sfL https://get.k3s.io | K3S_TOKEN=${NODE_TOKEN} sh -s - agent --server https://192.168.80.10:6443 --node-ip=${WORKER_ADDR} --node-external-ip=${WORKER_ADDR} -t ${NODE_TOKEN}
sudo kubectl apply -f /vagrant/loxilb-peer.yml
sudo kubectl apply -f /vagrant/nginx.yml
sudo kubectl apply -f /vagrant/udp.yml
sudo kubectl apply -f /vagrant/sctp.yml
Expand Down
2 changes: 1 addition & 1 deletion loxinet/loxinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func loxiNetInit() {
// Initialize the nlp subsystem
if !opts.Opts.NoNlp {
nlp.NlpRegister(NetAPIInit(opts.Opts.BgpPeerMode))
nlp.NlpInit(opts.Opts.BgpPeerMode)
nlp.NlpInit(opts.Opts.BgpPeerMode, opts.Opts.BlackList)
}

// Initialize the Prometheus subsystem
Expand Down
1 change: 1 addition & 0 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ var Opts struct {
RssEnable bool `long:"rss-enable" description:"Enable rss optimization(experimental)"`
EgrHooks bool `long:"egr-hooks" description:"Enable eBPF egress hooks(experimental)"`
BgpPeerMode bool `short:"r" long:"peer" description:"Run loxilb with goBGP only, no Datapath"`
BlackList string `long:"blacklist" description:"Regex string of blacklisted ports" default:"none"`
}
Loading