generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: walnuts1018 <[email protected]>
- Loading branch information
1 parent
08363a1
commit b0c7614
Showing
6 changed files
with
82 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package mock | ||
|
||
import ( | ||
"fmt" | ||
"net/netip" | ||
|
||
"github.com/vishvananda/netlink" | ||
) | ||
|
||
type linkName string | ||
|
||
type mockNAT struct { | ||
Clients map[netip.Addr]linkName | ||
} | ||
|
||
func NewMockNat() *mockNAT { | ||
return &mockNAT{ | ||
Clients: make(map[netip.Addr]linkName), | ||
} | ||
} | ||
|
||
func (m *mockNAT) Init() error { | ||
return nil | ||
} | ||
|
||
func (m *mockNAT) AddClient(addr netip.Addr, link netlink.Link) error { | ||
if link.Attrs() == nil { | ||
return fmt.Errorf("link.Attrs() returns nil") | ||
} | ||
m.Clients[addr] = linkName(link.Attrs().Name) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package mock | ||
|
||
import ( | ||
"net/netip" | ||
|
||
"github.com/vishvananda/netlink" | ||
) | ||
|
||
type mockTunnel struct { | ||
Tunnels map[netip.Addr]struct{} | ||
} | ||
|
||
func NewMockTunnel() mockTunnel { | ||
return mockTunnel{ | ||
Tunnels: make(map[netip.Addr]struct{}), | ||
} | ||
} | ||
|
||
func (m mockTunnel) AddPeer(addr netip.Addr) (netlink.Link, error) { | ||
m.Tunnels[addr] = struct{}{} | ||
link := &netlink.Dummy{ | ||
LinkAttrs: netlink.LinkAttrs{ | ||
Name: "dummy", | ||
Index: 1, | ||
}, | ||
} | ||
return link, nil | ||
} | ||
|
||
func (m mockTunnel) DelPeer(addr netip.Addr) error { | ||
delete(m.Tunnels, addr) | ||
return nil | ||
} | ||
|
||
func (m mockTunnel) Init() error { | ||
return nil | ||
} | ||
|
||
func (m mockTunnel) IsInitialized() bool { | ||
return true | ||
} |