Browse Source

add allocation backend that performs no data forwarding

For environments that support a host having a whole subnet, it is
useful to let Rudder just do the address allocation and use native
networking for data flows.
Eugene Yakubovich 10 năm trước cách đây
mục cha
commit
8661e6b383
2 tập tin đã thay đổi với 56 bổ sung0 xóa
  1. 53 0
      backend/alloc/alloc.go
  2. 3 0
      main.go

+ 53 - 0
backend/alloc/alloc.go

@@ -0,0 +1,53 @@
+package alloc
+
+import (
+	"fmt"
+	"net"
+
+	"github.com/coreos/rudder/backend"
+	"github.com/coreos/rudder/pkg/ip"
+	"github.com/coreos/rudder/pkg/task"
+	"github.com/coreos/rudder/subnet"
+)
+
+
+type AllocBackend struct {
+	sm   *subnet.SubnetManager
+	stop chan bool
+}
+
+func New(sm *subnet.SubnetManager) backend.Backend {
+	return &AllocBackend{
+		sm: sm,
+		stop: make(chan bool),
+	}
+}
+
+func (m *AllocBackend) Init(extIface *net.Interface, extIP net.IP, ipMasq bool) (ip.IP4Net, int, error) {
+	attrs := subnet.BaseAttrs{
+		PublicIP: ip.FromIP(extIP),
+	}
+
+	sn, err := m.sm.AcquireLease(ip.FromIP(extIP), &attrs, m.stop)
+	if err != nil {
+		if err == task.ErrCanceled {
+			return ip.IP4Net{}, 0, err
+		} else {
+			return ip.IP4Net{}, 0, fmt.Errorf("Failed to acquire lease: %v", err)
+		}
+	}
+
+	return sn, extIface.MTU, nil
+}
+
+func (m *AllocBackend) Run() {
+	m.sm.LeaseRenewer(m.stop)
+}
+
+func (m *AllocBackend) Stop() {
+	close(m.stop)
+}
+
+func (m *AllocBackend) Name() string {
+	return "allocation"
+}

+ 3 - 0
main.go

@@ -19,6 +19,7 @@ import (
 	"github.com/coreos/rudder/pkg/ip"
 	"github.com/coreos/rudder/pkg/task"
 	"github.com/coreos/rudder/subnet"
+	"github.com/coreos/rudder/backend/alloc"
 	"github.com/coreos/rudder/backend/udp"
 )
 
@@ -128,6 +129,8 @@ func newBackend() (backend.Backend, error) {
 	switch strings.ToLower(bt.Type) {
 	case "udp":
 		return udp.New(sm, config.Backend), nil
+	case "alloc":
+		return alloc.New(sm), nil
 	default:
 		return nil, fmt.Errorf("'%v': unknown backend type", bt.Type)
 	}