func (p *proxy) removeFromNoEndpointsList(servicePort ServicePort, tableFamily utilnftables.TableFamily) error {
	proto := servicePort.Protocol()
	port := uint16(servicePort.Port())
	if servicePort.ClusterIP().String() != "" {
		klog.V(6).Infof(" removing Service port %s from no endpoint list, cluster ip address: %s, protocol: %s port: %d ",
			servicePort.String(), servicePort.ClusterIP().String(), proto, port)
		if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, servicePort.ClusterIP().String(), port, nftables.K8sNoEndpointsSet, nftables.K8sFilterDoReject); err != nil {
			return err
		}
	}
	if extIPs := servicePort.ExternalIPStrings(); len(extIPs) != 0 {
		for _, extIP := range extIPs {
			klog.V(6).Infof(" removing Service port %s from no endpoint list, external ip address: %s, protocol: %s port: %d ",
				servicePort.String(), extIP, proto, port)
			if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, extIP, port, nftables.K8sNoEndpointsSet, nftables.K8sFilterDoReject); err != nil {
				return err
			}
		}
	}
	if lbIPs := servicePort.LoadBalancerIPStrings(); len(lbIPs) != 0 {
		for _, lbIP := range lbIPs {
			klog.V(6).Infof(" removing Service port %s from no endpoint list, loadbalancer ip address: %s, protocol: %s port: %d ",
				servicePort.String(), lbIP, proto, port)
			if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, lbIP, port, nftables.K8sNoEndpointsSet, nftables.K8sFilterDoReject); err != nil {
				return err
			}
		}
	}
	return nil
}
removeFromNoEndpointsList removes to No Endpoints List all IPs/port pairs of a specific servicePort
package proxy
import (
	utilnftables "github.com/google/nftables"
	"github.com/sbezverk/nfproxy/pkg/nftables"
	"k8s.io/klog"
)
func (p *proxy) addServicePortToSets(servicePort ServicePort, tableFamily utilnftables.TableFamily, svcID string) error {
	proto := servicePort.Protocol()
	port := uint16(servicePort.Port())
	clusterIP := servicePort.ClusterIP().String()
	if err := nftables.AddToSet(p.nfti, tableFamily, proto, clusterIP, port, nftables.K8sClusterIPSet, nftables.K8sSvcPrefix+svcID); err != nil {
		return err
	}
	if err := nftables.AddToSet(p.nfti, tableFamily, proto, clusterIP, port, nftables.K8sMarkMasqSet, nftables.K8sNATDoMarkMasq); err != nil {
		return err
	}
	if extIPs := servicePort.ExternalIPStrings(); len(extIPs) != 0 {
		for _, extIP := range extIPs {
			if err := nftables.AddToSet(p.nfti, tableFamily, proto, extIP, port, nftables.K8sExternalIPSet, nftables.K8sSvcPrefix+svcID); err != nil {
				return err
			}
			if err := nftables.AddToSet(p.nfti, tableFamily, proto, extIP, port, nftables.K8sMarkMasqSet, nftables.K8sNATDoMarkMasq); err != nil {
				return err
			}
		}
	}
	if lbIPs := servicePort.LoadBalancerIPStrings(); len(lbIPs) != 0 {
		for _, lbIP := range lbIPs {
			if err := nftables.AddToSet(p.nfti, tableFamily, proto, lbIP, port, nftables.K8sLoadbalancerIPSet, nftables.K8sSvcPrefix+svcID); err != nil {
				return err
			}
			if err := nftables.AddToSet(p.nfti, tableFamily, proto, lbIP, port, nftables.K8sMarkMasqSet, nftables.K8sNATDoMarkMasq); err != nil {
				return err
			}
		}
	}
	if nodePort := servicePort.NodePort(); nodePort != 0 {
		if err := nftables.AddToNodeportSet(p.nfti, tableFamily, proto, uint16(nodePort), nftables.K8sSvcPrefix+svcID); err != nil {
			return err
		}
	}
	return nil
}
func (p *proxy) removeServicePortFromSets(servicePort ServicePort, tableFamily utilnftables.TableFamily, svcID string) error {
	svcName := servicePort.(*BaseServiceInfo).svcName
	svcNamespace := servicePort.(*BaseServiceInfo).svcNamespace
	storedSvc, err := p.cache.getLastKnownSvcFromCache(svcName, svcNamespace)
	if err != nil {
		return err
	}
	proto := servicePort.Protocol()
	port := uint16(servicePort.Port())
	clusterIP := storedSvc.Spec.ClusterIP
	if clusterIP != "" {
		klog.V(6).Infof("removing Service port %s from Cluster IP Set, cluster ip address: %s, protocol: %s port: %d ",
			servicePort.String(), clusterIP, proto, port)
		if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, clusterIP, port, nftables.K8sClusterIPSet, nftables.K8sSvcPrefix+svcID); err != nil {
			return err
		}
		if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, clusterIP, port, nftables.K8sMarkMasqSet, nftables.K8sNATDoMarkMasq); err != nil {
			return err
		}
	}
	if extIPs := storedSvc.Spec.ExternalIPs; len(extIPs) != 0 {
		for _, extIP := range extIPs {
			klog.V(6).Infof("removing Service port %s from External IP Set, external ip address: %s, protocol: %s port: %d ",
				servicePort.String(), extIP, proto, port)
			if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, extIP, port, nftables.K8sExternalIPSet, nftables.K8sSvcPrefix+svcID); err != nil {
				return err
			}
			if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, extIP, port, nftables.K8sMarkMasqSet, nftables.K8sNATDoMarkMasq); err != nil {
				return err
			}
		}
	}
	for _, lbIP := range storedSvc.Status.LoadBalancer.Ingress {
		klog.V(6).Infof("removing Service port %s from LoadBalancer Set, loadbalancer ip address: %s, protocol: %s port: %d ",
			servicePort.String(), lbIP, proto, port)
		if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, lbIP.IP, port, nftables.K8sLoadbalancerIPSet, nftables.K8sSvcPrefix+svcID); err != nil {
			return err
		}
		if err := nftables.RemoveFromSet(p.nfti, tableFamily, proto, lbIP.IP, port, nftables.K8sMarkMasqSet, nftables.K8sNATDoMarkMasq); err != nil {
			return err
		}
	}
	for _, nodePort := range storedSvc.Spec.Ports {
		if nodePort.NodePort == 0 {
			continue
		}
		klog.V(6).Infof("removing Service port %s from NodePortSet, protocol: %s port: %d ", servicePort.String(), proto, nodePort.NodePort)
		if err := nftables.RemoveFromNodeportSet(p.nfti, tableFamily, proto, uint16(nodePort.NodePort), nftables.K8sSvcPrefix+svcID); err != nil {
			return err
		}
	}
	return nil
}
func (p *proxy) addToNoEndpointsList(servicePort ServicePort, tableFamily utilnftables.TableFamily) error {
	proto := servicePort.Protocol()
	port := uint16(servicePort.Port())
	if err := nftables.AddToSet(p.nfti, tableFamily, proto, servicePort.ClusterIP().String(), port, nftables.K8sNoEndpointsSet, nftables.K8sFilterDoReject); err != nil {
		return err
	}
	if extIPs := servicePort.ExternalIPStrings(); len(extIPs) != 0 {
		for _, extIP := range extIPs {
			if err := nftables.AddToSet(p.nfti, tableFamily, proto, extIP, port, nftables.K8sNoEndpointsSet, nftables.K8sFilterDoReject); err != nil {
				return err
			}
		}
	}
	if lbIPs := servicePort.LoadBalancerIPStrings(); len(lbIPs) != 0 {
		for _, lbIP := range lbIPs {
			if err := nftables.AddToSet(p.nfti, tableFamily, proto, lbIP, port, nftables.K8sNoEndpointsSet, nftables.K8sFilterDoReject); err != nil {
				return err
			}
		}
	}
	return nil
}