mirror of
https://github.com/luscis/openlan.git
synced 2025-09-27 04:46:02 +08:00
fea: access in name proxy.
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := config.NewPoint()
|
c := config.NewAccess()
|
||||||
p := access.NewPoint(c)
|
p := access.NewAccess(c)
|
||||||
|
|
||||||
p.Initialize()
|
p.Initialize()
|
||||||
libol.Go(p.Start)
|
libol.Go(p.Start)
|
||||||
|
@@ -5,11 +5,11 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Point struct {
|
type Access struct {
|
||||||
Cmd
|
Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Point) Url(prefix, name string) string {
|
func (u Access) Url(prefix, name string) string {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return prefix + "/api/point"
|
return prefix + "/api/point"
|
||||||
} else {
|
} else {
|
||||||
@@ -17,7 +17,7 @@ func (u Point) Url(prefix, name string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Point) Tmpl() string {
|
func (u Access) Tmpl() string {
|
||||||
return `# total {{ len . }}
|
return `# total {{ len . }}
|
||||||
{{ps -16 "uuid"}} {{ps -8 "alive"}} {{ ps -8 "device" }} {{ps -16 "alias"}} {{ps -8 "user"}} {{ps -22 "remote"}} {{ps -8 "network"}} {{ ps -6 "state"}}
|
{{ps -16 "uuid"}} {{ps -8 "alive"}} {{ ps -8 "device" }} {{ps -16 "alias"}} {{ps -8 "user"}} {{ps -22 "remote"}} {{ps -8 "network"}} {{ ps -6 "state"}}
|
||||||
{{- range . }}
|
{{- range . }}
|
||||||
@@ -26,10 +26,10 @@ func (u Point) Tmpl() string {
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Point) List(c *cli.Context) error {
|
func (u Access) List(c *cli.Context) error {
|
||||||
url := u.Url(c.String("url"), "")
|
url := u.Url(c.String("url"), "")
|
||||||
clt := u.NewHttp(c.String("token"))
|
clt := u.NewHttp(c.String("token"))
|
||||||
var items []schema.Point
|
var items []schema.Access
|
||||||
if err := clt.GetJSON(url, &items); err != nil {
|
if err := clt.GetJSON(url, &items); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ func (u Point) List(c *cli.Context) error {
|
|||||||
return u.Out(items, c.String("format"), u.Tmpl())
|
return u.Out(items, c.String("format"), u.Tmpl())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Point) Commands() *cli.Command {
|
func (u Access) Commands() *cli.Command {
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "access",
|
Name: "access",
|
||||||
Usage: "access to this switch",
|
Usage: "access to this switch",
|
||||||
|
@@ -58,10 +58,10 @@ func (u Config) Check(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check OLAP configurations.
|
// Check OLAP configurations.
|
||||||
out.Info("%15s: %s", "check", "point")
|
out.Info("%15s: %s", "check", "access")
|
||||||
file = filepath.Join(dir, "point.json")
|
file = filepath.Join(dir, "access", "access.json")
|
||||||
if err := libol.FileExist(file); err == nil {
|
if err := libol.FileExist(file); err == nil {
|
||||||
obj := &config.Point{}
|
obj := &config.Access{}
|
||||||
if err := libol.UnmarshalLoad(obj, file); err != nil {
|
if err := libol.UnmarshalLoad(obj, file); err != nil {
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
out.Warn("%15s: %s", filepath.Base(file), err)
|
||||||
} else {
|
} else {
|
||||||
@@ -124,7 +124,7 @@ func (u Config) Check(c *cli.Context) error {
|
|||||||
pattern = filepath.Join(dir, "switch", "link", "*.json")
|
pattern = filepath.Join(dir, "switch", "link", "*.json")
|
||||||
if files, err := filepath.Glob(pattern); err == nil {
|
if files, err := filepath.Glob(pattern); err == nil {
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
var obj []config.Point
|
var obj []config.Access
|
||||||
if err := libol.UnmarshalLoad(&obj, file); err != nil {
|
if err := libol.UnmarshalLoad(&obj, file); err != nil {
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
out.Warn("%15s: %s", filepath.Base(file), err)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -154,7 +154,7 @@ func (u Network) Commands(app *api.App) {
|
|||||||
},
|
},
|
||||||
Action: u.Save,
|
Action: u.Save,
|
||||||
},
|
},
|
||||||
Point{}.Commands(),
|
Access{}.Commands(),
|
||||||
Qos{}.Commands(),
|
Qos{}.Commands(),
|
||||||
VPNClient{}.Commands(),
|
VPNClient{}.Commands(),
|
||||||
OpenVPN{}.Commands(),
|
OpenVPN{}.Commands(),
|
||||||
|
13
dist/rootfs/etc/openlan/name/name.yaml.default
vendored
13
dist/rootfs/etc/openlan/name/name.yaml.default
vendored
@@ -1,12 +1,15 @@
|
|||||||
|
|
||||||
listen: 127.0.0.1
|
listen: 127.0.0.1
|
||||||
|
access:
|
||||||
|
- connection: <remote-server>
|
||||||
|
protocol: tcp
|
||||||
|
username: <username>@<network>
|
||||||
|
password: <password>
|
||||||
|
forward:
|
||||||
|
- 8.8.8.8
|
||||||
|
- 8.8.4.4
|
||||||
nameto: 114.114.114.114
|
nameto: 114.114.114.114
|
||||||
backends:
|
backends:
|
||||||
- server: 192.168.11.1
|
|
||||||
nameto: 8.8.8.8
|
|
||||||
match:
|
|
||||||
- openai.com
|
|
||||||
- chatgpt.com
|
|
||||||
- server: 192.168.11.2
|
- server: 192.168.11.2
|
||||||
nameto: 8.8.8.8
|
nameto: 8.8.8.8
|
||||||
match:
|
match:
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/network"
|
"github.com/luscis/openlan/pkg/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pointer interface {
|
type Acceser interface {
|
||||||
Addr() string
|
Addr() string
|
||||||
IfName() string
|
IfName() string
|
||||||
IfAddr() string
|
IfAddr() string
|
||||||
@@ -24,27 +24,27 @@ type Pointer interface {
|
|||||||
Record() map[string]int64
|
Record() map[string]int64
|
||||||
Tenant() string
|
Tenant() string
|
||||||
Alias() string
|
Alias() string
|
||||||
Config() *config.Point
|
Config() *config.Access
|
||||||
Network() *models.Network
|
Network() *models.Network
|
||||||
}
|
}
|
||||||
|
|
||||||
type MixPoint struct {
|
type MixAccess struct {
|
||||||
uuid string
|
uuid string
|
||||||
worker *Worker
|
worker *Worker
|
||||||
config *config.Point
|
config *config.Access
|
||||||
out *libol.SubLogger
|
out *libol.SubLogger
|
||||||
http *http.Http
|
http *http.Http
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMixPoint(config *config.Point) MixPoint {
|
func NewMixAccess(config *config.Access) MixAccess {
|
||||||
return MixPoint{
|
return MixAccess{
|
||||||
worker: NewWorker(config),
|
worker: NewWorker(config),
|
||||||
config: config,
|
config: config,
|
||||||
out: libol.NewSubLogger(config.Id()),
|
out: libol.NewSubLogger(config.Id()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Initialize() {
|
func (p *MixAccess) Initialize() {
|
||||||
libol.Info("MixAccess.Initialize")
|
libol.Info("MixAccess.Initialize")
|
||||||
p.worker.SetUUID(p.UUID())
|
p.worker.SetUUID(p.UUID())
|
||||||
p.worker.Initialize()
|
p.worker.Initialize()
|
||||||
@@ -53,7 +53,7 @@ func (p *MixPoint) Initialize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Start() {
|
func (p *MixAccess) Start() {
|
||||||
p.out.Info("MixAccess.Start %s", runtime.GOOS)
|
p.out.Info("MixAccess.Start %s", runtime.GOOS)
|
||||||
if p.config.PProf != "" {
|
if p.config.PProf != "" {
|
||||||
f := libol.PProf{Listen: p.config.PProf}
|
f := libol.PProf{Listen: p.config.PProf}
|
||||||
@@ -62,7 +62,7 @@ func (p *MixPoint) Start() {
|
|||||||
p.worker.Start()
|
p.worker.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Stop() {
|
func (p *MixAccess) Stop() {
|
||||||
defer libol.Catch("MixAccess.Stop")
|
defer libol.Catch("MixAccess.Stop")
|
||||||
if p.http != nil {
|
if p.http != nil {
|
||||||
p.http.Shutdown()
|
p.http.Shutdown()
|
||||||
@@ -70,14 +70,14 @@ func (p *MixPoint) Stop() {
|
|||||||
p.worker.Stop()
|
p.worker.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) UUID() string {
|
func (p *MixAccess) UUID() string {
|
||||||
if p.uuid == "" {
|
if p.uuid == "" {
|
||||||
p.uuid = libol.GenString(13)
|
p.uuid = libol.GenString(13)
|
||||||
}
|
}
|
||||||
return p.uuid
|
return p.uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Status() libol.SocketStatus {
|
func (p *MixAccess) Status() libol.SocketStatus {
|
||||||
client := p.Client()
|
client := p.Client()
|
||||||
if client == nil {
|
if client == nil {
|
||||||
return 0
|
return 0
|
||||||
@@ -85,11 +85,11 @@ func (p *MixPoint) Status() libol.SocketStatus {
|
|||||||
return client.Status()
|
return client.Status()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Addr() string {
|
func (p *MixAccess) Addr() string {
|
||||||
return p.config.Connection
|
return p.config.Connection
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) IfName() string {
|
func (p *MixAccess) IfName() string {
|
||||||
device := p.Device()
|
device := p.Device()
|
||||||
if device == nil {
|
if device == nil {
|
||||||
return ""
|
return ""
|
||||||
@@ -97,54 +97,54 @@ func (p *MixPoint) IfName() string {
|
|||||||
return device.Name()
|
return device.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Client() libol.SocketClient {
|
func (p *MixAccess) Client() libol.SocketClient {
|
||||||
if p.worker.conWorker == nil {
|
if p.worker.conWorker == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return p.worker.conWorker.client
|
return p.worker.conWorker.client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Device() network.Taper {
|
func (p *MixAccess) Device() network.Taper {
|
||||||
if p.worker.tapWorker == nil {
|
if p.worker.tapWorker == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return p.worker.tapWorker.device
|
return p.worker.tapWorker.device
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) UpTime() int64 {
|
func (p *MixAccess) UpTime() int64 {
|
||||||
return p.worker.UpTime()
|
return p.worker.UpTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) IfAddr() string {
|
func (p *MixAccess) IfAddr() string {
|
||||||
return p.worker.ifAddr
|
return p.worker.ifAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Tenant() string {
|
func (p *MixAccess) Tenant() string {
|
||||||
return p.config.Network
|
return p.config.Network
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) User() string {
|
func (p *MixAccess) User() string {
|
||||||
return p.config.Username
|
return p.config.Username
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Alias() string {
|
func (p *MixAccess) Alias() string {
|
||||||
return p.config.Alias
|
return p.config.Alias
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Record() map[string]int64 {
|
func (p *MixAccess) Record() map[string]int64 {
|
||||||
rt := p.worker.conWorker.record
|
rt := p.worker.conWorker.record
|
||||||
// TODO padding data from tapWorker
|
// TODO padding data from tapWorker
|
||||||
return rt.Data()
|
return rt.Data()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Config() *config.Point {
|
func (p *MixAccess) Config() *config.Access {
|
||||||
return p.config
|
return p.config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Network() *models.Network {
|
func (p *MixAccess) Network() *models.Network {
|
||||||
return p.worker.network
|
return p.worker.network
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MixPoint) Protocol() string {
|
func (p *MixAccess) Protocol() string {
|
||||||
return p.config.Protocol
|
return p.config.Protocol
|
||||||
}
|
}
|
@@ -7,41 +7,41 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/network"
|
"github.com/luscis/openlan/pkg/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Point struct {
|
type Access struct {
|
||||||
MixPoint
|
MixAccess
|
||||||
// private
|
// private
|
||||||
brName string
|
brName string
|
||||||
addr string
|
addr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPoint(config *config.Point) *Point {
|
func NewAccess(config *config.Access) *Access {
|
||||||
p := Point{
|
p := Access{
|
||||||
brName: config.Interface.Bridge,
|
brName: config.Interface.Bridge,
|
||||||
MixPoint: NewMixPoint(config),
|
MixAccess: NewMixAccess(config),
|
||||||
}
|
}
|
||||||
return &p
|
return &p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) Initialize() {
|
func (p *Access) Initialize() {
|
||||||
w := p.worker
|
w := p.worker
|
||||||
w.listener.AddAddr = p.AddAddr
|
w.listener.AddAddr = p.AddAddr
|
||||||
w.listener.DelAddr = p.DelAddr
|
w.listener.DelAddr = p.DelAddr
|
||||||
|
|
||||||
p.MixPoint.Initialize()
|
p.MixAccess.Initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) routeAdd(prefix string) ([]byte, error) {
|
func (p *Access) routeAdd(prefix string) ([]byte, error) {
|
||||||
network.RouteDel("", prefix, "")
|
network.RouteDel("", prefix, "")
|
||||||
out, err := network.RouteAdd(p.IfName(), prefix, "")
|
out, err := network.RouteAdd(p.IfName(), prefix, "")
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) AddAddr(ipStr string) error {
|
func (p *Access) AddAddr(ipStr string) error {
|
||||||
if ipStr == "" {
|
if ipStr == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// add point-to-point
|
// add Access-to-Access
|
||||||
ips := strings.SplitN(ipStr, "/", 2)
|
ips := strings.SplitN(ipStr, "/", 2)
|
||||||
out, err := network.AddrAdd(p.IfName(), ips[0], ips[0])
|
out, err := network.AddrAdd(p.IfName(), ips[0], ips[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -62,7 +62,7 @@ func (p *Point) AddAddr(ipStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) DelAddr(ipStr string) error {
|
func (p *Access) DelAddr(ipStr string) error {
|
||||||
// delete directly route.
|
// delete directly route.
|
||||||
out, err := network.RouteDel(p.IfName(), ipStr, "")
|
out, err := network.RouteDel(p.IfName(), ipStr, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -70,7 +70,7 @@ func (p *Point) DelAddr(ipStr string) error {
|
|||||||
}
|
}
|
||||||
p.out.Info("Access.DelAddr: route %s via %s", ipStr, p.IfName())
|
p.out.Info("Access.DelAddr: route %s via %s", ipStr, p.IfName())
|
||||||
|
|
||||||
// delete point-to-point
|
// delete Access-to-Access
|
||||||
ip4 := strings.SplitN(ipStr, "/", 2)[0]
|
ip4 := strings.SplitN(ipStr, "/", 2)[0]
|
||||||
out, err = network.AddrDel(p.IfName(), ip4)
|
out, err = network.AddrDel(p.IfName(), ip4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -83,7 +83,7 @@ func (p *Point) DelAddr(ipStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) AddRoute() error {
|
func (p *Access) AddRoute() error {
|
||||||
to := p.config.Forward
|
to := p.config.Forward
|
||||||
if to == nil {
|
if to == nil {
|
||||||
return nil
|
return nil
|
@@ -7,8 +7,8 @@ import (
|
|||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Point struct {
|
type Access struct {
|
||||||
MixPoint
|
MixAccess
|
||||||
// private
|
// private
|
||||||
brName string
|
brName string
|
||||||
ipMtu int
|
ipMtu int
|
||||||
@@ -19,30 +19,30 @@ type Point struct {
|
|||||||
uuid string
|
uuid string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPoint(config *config.Point) *Point {
|
func NewAccess(config *config.Access) *Access {
|
||||||
ipMtu := config.Interface.IPMtu
|
ipMtu := config.Interface.IPMtu
|
||||||
if ipMtu == 0 {
|
if ipMtu == 0 {
|
||||||
ipMtu = 1500
|
ipMtu = 1500
|
||||||
}
|
}
|
||||||
p := Point{
|
p := Access{
|
||||||
ipMtu: ipMtu,
|
ipMtu: ipMtu,
|
||||||
brName: config.Interface.Bridge,
|
brName: config.Interface.Bridge,
|
||||||
MixPoint: NewMixPoint(config),
|
MixAccess: NewMixAccess(config),
|
||||||
}
|
}
|
||||||
return &p
|
return &p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) Initialize() {
|
func (p *Access) Initialize() {
|
||||||
w := p.worker
|
w := p.worker
|
||||||
|
|
||||||
w.listener.AddAddr = p.AddAddr
|
w.listener.AddAddr = p.AddAddr
|
||||||
w.listener.DelAddr = p.DelAddr
|
w.listener.DelAddr = p.DelAddr
|
||||||
w.listener.OnTap = p.OnTap
|
w.listener.OnTap = p.OnTap
|
||||||
|
|
||||||
p.MixPoint.Initialize()
|
p.MixAccess.Initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) DelAddr(ipStr string) error {
|
func (p *Access) DelAddr(ipStr string) error {
|
||||||
if p.link == nil || ipStr == "" {
|
if p.link == nil || ipStr == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ func (p *Point) DelAddr(ipStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) AddAddr(ipStr string) error {
|
func (p *Access) AddAddr(ipStr string) error {
|
||||||
if ipStr == "" || p.link == nil {
|
if ipStr == "" || p.link == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ func (p *Point) AddAddr(ipStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) UpBr(name string) *netlink.Bridge {
|
func (p *Access) UpBr(name string) *netlink.Bridge {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ func (p *Point) UpBr(name string) *netlink.Bridge {
|
|||||||
return br
|
return br
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) OnTap(w *TapWorker) error {
|
func (p *Access) OnTap(w *TapWorker) error {
|
||||||
p.out.Info("Access.OnTap")
|
p.out.Info("Access.OnTap")
|
||||||
tap := w.device
|
tap := w.device
|
||||||
name := tap.Name()
|
name := tap.Name()
|
||||||
@@ -141,7 +141,7 @@ func (p *Point) OnTap(w *TapWorker) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) AddRoute() error {
|
func (p *Access) AddRoute() error {
|
||||||
to := p.config.Forward
|
to := p.config.Forward
|
||||||
route := p.Network()
|
route := p.Network()
|
||||||
if to == nil || route == nil {
|
if to == nil || route == nil {
|
@@ -9,31 +9,31 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/network"
|
"github.com/luscis/openlan/pkg/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Point struct {
|
type Access struct {
|
||||||
MixPoint
|
MixAccess
|
||||||
// private
|
// private
|
||||||
brName string
|
brName string
|
||||||
addr string
|
addr string
|
||||||
routes []*models.Route
|
routes []*models.Route
|
||||||
config *config.Point
|
config *config.Access
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPoint(config *config.Point) *Point {
|
func NewAccess(config *config.Access) *Access {
|
||||||
p := Point{
|
p := Access{
|
||||||
brName: config.Interface.Bridge,
|
brName: config.Interface.Bridge,
|
||||||
MixPoint: NewMixPoint(config),
|
MixAccess: NewMixAccess(config),
|
||||||
}
|
}
|
||||||
return &p
|
return &p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) Initialize() {
|
func (p *Access) Initialize() {
|
||||||
p.worker.listener.AddAddr = p.AddAddr
|
p.worker.listener.AddAddr = p.AddAddr
|
||||||
p.worker.listener.DelAddr = p.DelAddr
|
p.worker.listener.DelAddr = p.DelAddr
|
||||||
p.worker.listener.OnTap = p.OnTap
|
p.worker.listener.OnTap = p.OnTap
|
||||||
p.MixPoint.Initialize()
|
p.MixAccess.Initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) OnTap(w *TapWorker) error {
|
func (p *Access) OnTap(w *TapWorker) error {
|
||||||
// clean routes previous
|
// clean routes previous
|
||||||
routes := make([]*models.Route, 0, 32)
|
routes := make([]*models.Route, 0, 32)
|
||||||
if err := libol.UnmarshalLoad(&routes, ".routes.json"); err == nil {
|
if err := libol.UnmarshalLoad(&routes, ".routes.json"); err == nil {
|
||||||
@@ -45,11 +45,11 @@ func (p *Point) OnTap(w *TapWorker) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) Trim(out []byte) string {
|
func (p *Access) Trim(out []byte) string {
|
||||||
return strings.TrimSpace(string(out))
|
return strings.TrimSpace(string(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) AddAddr(ipStr string) error {
|
func (p *Access) AddAddr(ipStr string) error {
|
||||||
if ipStr == "" {
|
if ipStr == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ func (p *Point) AddAddr(ipStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) DelAddr(ipStr string) error {
|
func (p *Access) DelAddr(ipStr string) error {
|
||||||
ipv4 := strings.Split(ipStr, "/")[0]
|
ipv4 := strings.Split(ipStr, "/")[0]
|
||||||
out, err := network.AddrDel(p.IfName(), ipv4)
|
out, err := network.AddrDel(p.IfName(), ipv4)
|
||||||
if err != nil {
|
if err != nil {
|
@@ -2,13 +2,14 @@ package http
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/luscis/openlan/pkg/libol"
|
"github.com/luscis/openlan/pkg/libol"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Http struct {
|
type Http struct {
|
||||||
pointer Pointer
|
acc Accesser
|
||||||
listen string
|
listen string
|
||||||
server *http.Server
|
server *http.Server
|
||||||
crtFile string
|
crtFile string
|
||||||
@@ -18,11 +19,11 @@ type Http struct {
|
|||||||
token string
|
token string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttp(pointer Pointer) (h *Http) {
|
func NewHttp(acc Accesser) (h *Http) {
|
||||||
h = &Http{
|
h = &Http{
|
||||||
pointer: pointer,
|
acc: acc,
|
||||||
}
|
}
|
||||||
if config := pointer.Config(); config != nil {
|
if config := acc.Config(); config != nil {
|
||||||
if config.Http != nil {
|
if config.Http != nil {
|
||||||
h.listen = config.Http.Listen
|
h.listen = config.Http.Listen
|
||||||
h.pubDir = config.Http.Public
|
h.pubDir = config.Http.Public
|
||||||
@@ -80,17 +81,17 @@ func (h *Http) LoadRouter() {
|
|||||||
router.HandleFunc("/current/uuid", func(w http.ResponseWriter, r *http.Request) {
|
router.HandleFunc("/current/uuid", func(w http.ResponseWriter, r *http.Request) {
|
||||||
format := GetQueryOne(r, "format")
|
format := GetQueryOne(r, "format")
|
||||||
if format == "yaml" {
|
if format == "yaml" {
|
||||||
ResponseYaml(w, h.pointer.UUID())
|
ResponseYaml(w, h.acc.UUID())
|
||||||
} else {
|
} else {
|
||||||
ResponseJson(w, h.pointer.UUID())
|
ResponseJson(w, h.acc.UUID())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
router.HandleFunc("/current/config", func(w http.ResponseWriter, r *http.Request) {
|
router.HandleFunc("/current/config", func(w http.ResponseWriter, r *http.Request) {
|
||||||
format := GetQueryOne(r, "format")
|
format := GetQueryOne(r, "format")
|
||||||
if format == "yaml" {
|
if format == "yaml" {
|
||||||
ResponseYaml(w, h.pointer.Config())
|
ResponseYaml(w, h.acc.Config())
|
||||||
} else {
|
} else {
|
||||||
ResponseJson(w, h.pointer.Config())
|
ResponseJson(w, h.acc.Config())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ package http
|
|||||||
|
|
||||||
import "github.com/luscis/openlan/pkg/config"
|
import "github.com/luscis/openlan/pkg/config"
|
||||||
|
|
||||||
type Pointer interface {
|
type Accesser interface {
|
||||||
UUID() string
|
UUID() string
|
||||||
Config() *config.Point
|
Config() *config.Access
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ type SocketWorker struct {
|
|||||||
keepalive KeepAlive
|
keepalive KeepAlive
|
||||||
done chan bool
|
done chan bool
|
||||||
ticker *time.Ticker
|
ticker *time.Ticker
|
||||||
pinCfg *config.Point
|
pinCfg *config.Access
|
||||||
eventQueue chan *WorkerEvent
|
eventQueue chan *WorkerEvent
|
||||||
writeQueue chan *libol.FrameMessage
|
writeQueue chan *libol.FrameMessage
|
||||||
jobber []jobTimer
|
jobber []jobTimer
|
||||||
@@ -52,7 +52,7 @@ type SocketWorker struct {
|
|||||||
wlFrame *libol.FrameMessage // Last frame from write.
|
wlFrame *libol.FrameMessage // Last frame from write.
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSocketWorker(client libol.SocketClient, c *config.Point) *SocketWorker {
|
func NewSocketWorker(client libol.SocketClient, c *config.Access) *SocketWorker {
|
||||||
t := &SocketWorker{
|
t := &SocketWorker{
|
||||||
client: client,
|
client: client,
|
||||||
network: models.NewNetwork(c.Network, c.Interface.Address),
|
network: models.NewNetwork(c.Network, c.Interface.Address),
|
||||||
|
@@ -32,7 +32,7 @@ type TapWorker struct {
|
|||||||
ether TunEther
|
ether TunEther
|
||||||
neighbor Neighbors
|
neighbor Neighbors
|
||||||
devCfg network.TapConfig
|
devCfg network.TapConfig
|
||||||
pinCfg *config.Point
|
pinCfg *config.Access
|
||||||
ifAddr string
|
ifAddr string
|
||||||
writeQueue chan *libol.FrameMessage
|
writeQueue chan *libol.FrameMessage
|
||||||
done chan bool
|
done chan bool
|
||||||
@@ -40,7 +40,7 @@ type TapWorker struct {
|
|||||||
eventQueue chan *WorkerEvent
|
eventQueue chan *WorkerEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTapWorker(devCfg network.TapConfig, pinCfg *config.Point) (a *TapWorker) {
|
func NewTapWorker(devCfg network.TapConfig, pinCfg *config.Access) (a *TapWorker) {
|
||||||
a = &TapWorker{
|
a = &TapWorker{
|
||||||
devCfg: devCfg,
|
devCfg: devCfg,
|
||||||
pinCfg: pinCfg,
|
pinCfg: pinCfg,
|
||||||
|
@@ -2,23 +2,24 @@ package access
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/chzyer/readline"
|
|
||||||
"github.com/luscis/openlan/pkg/libol"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/chzyer/readline"
|
||||||
|
"github.com/luscis/openlan/pkg/libol"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Terminal struct {
|
type Terminal struct {
|
||||||
Pointer Pointer
|
Acceser Acceser
|
||||||
Console *readline.Instance
|
Console *readline.Instance
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTerminal(pointer Pointer) *Terminal {
|
func NewTerminal(Acceser Acceser) *Terminal {
|
||||||
t := &Terminal{Pointer: pointer}
|
t := &Terminal{Acceser: Acceser}
|
||||||
completer := readline.NewPrefixCompleter(
|
completer := readline.NewPrefixCompleter(
|
||||||
readline.PcItem("quit"),
|
readline.PcItem("quit"),
|
||||||
readline.PcItem("help"),
|
readline.PcItem("help"),
|
||||||
@@ -52,7 +53,7 @@ func NewTerminal(pointer Pointer) *Terminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) Prompt() string {
|
func (t *Terminal) Prompt() string {
|
||||||
user := t.Pointer.User()
|
user := t.Acceser.User()
|
||||||
cur := os.Getenv("PWD")
|
cur := os.Getenv("PWD")
|
||||||
home := os.Getenv("HOME")
|
home := os.Getenv("HOME")
|
||||||
if strings.HasPrefix(cur, home) {
|
if strings.HasPrefix(cur, home) {
|
||||||
@@ -71,24 +72,24 @@ func (t *Terminal) CmdShow(args []string) {
|
|||||||
}
|
}
|
||||||
switch action {
|
switch action {
|
||||||
case "record":
|
case "record":
|
||||||
v := t.Pointer.Record()
|
v := t.Acceser.Record()
|
||||||
if out, err := libol.Marshal(v, true); err == nil {
|
if out, err := libol.Marshal(v, true); err == nil {
|
||||||
fmt.Printf("%s\n", out)
|
fmt.Printf("%s\n", out)
|
||||||
}
|
}
|
||||||
case "statistics":
|
case "statistics":
|
||||||
if c := t.Pointer.Client(); c != nil {
|
if c := t.Acceser.Client(); c != nil {
|
||||||
v := c.Statistics()
|
v := c.Statistics()
|
||||||
if out, err := libol.Marshal(v, true); err == nil {
|
if out, err := libol.Marshal(v, true); err == nil {
|
||||||
fmt.Printf("%s\n", out)
|
fmt.Printf("%s\n", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "config":
|
case "config":
|
||||||
cfg := t.Pointer.Config()
|
cfg := t.Acceser.Config()
|
||||||
if str, err := libol.Marshal(cfg, true); err == nil {
|
if str, err := libol.Marshal(cfg, true); err == nil {
|
||||||
fmt.Printf("%s\n", str)
|
fmt.Printf("%s\n", str)
|
||||||
}
|
}
|
||||||
case "network":
|
case "network":
|
||||||
cfg := t.Pointer.Network()
|
cfg := t.Acceser.Network()
|
||||||
if str, err := libol.Marshal(cfg, true); err == nil {
|
if str, err := libol.Marshal(cfg, true); err == nil {
|
||||||
fmt.Printf("%s\n", str)
|
fmt.Printf("%s\n", str)
|
||||||
}
|
}
|
||||||
@@ -99,10 +100,10 @@ func (t *Terminal) CmdShow(args []string) {
|
|||||||
Device string
|
Device string
|
||||||
Status string
|
Status string
|
||||||
}{
|
}{
|
||||||
UUID: t.Pointer.UUID(),
|
UUID: t.Acceser.UUID(),
|
||||||
UpTime: t.Pointer.UpTime(),
|
UpTime: t.Acceser.UpTime(),
|
||||||
Device: t.Pointer.IfName(),
|
Device: t.Acceser.IfName(),
|
||||||
Status: t.Pointer.Status().String(),
|
Status: t.Acceser.Status().String(),
|
||||||
}
|
}
|
||||||
if str, err := libol.Marshal(v, true); err == nil {
|
if str, err := libol.Marshal(v, true); err == nil {
|
||||||
fmt.Printf("%s\n", str)
|
fmt.Printf("%s\n", str)
|
||||||
|
@@ -82,7 +82,7 @@ type PrefixRule struct {
|
|||||||
NextHop net.IP
|
NextHop net.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSocketClient(p *config.Point) libol.SocketClient {
|
func GetSocketClient(p *config.Access) libol.SocketClient {
|
||||||
crypt := p.Crypt
|
crypt := p.Crypt
|
||||||
block := libol.NewBlockCrypt(crypt.Algo, crypt.Secret)
|
block := libol.NewBlockCrypt(crypt.Algo, crypt.Secret)
|
||||||
switch p.Protocol {
|
switch p.Protocol {
|
||||||
@@ -142,7 +142,7 @@ func GetSocketClient(p *config.Point) libol.SocketClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTapCfg(c *config.Point) network.TapConfig {
|
func GetTapCfg(c *config.Access) network.TapConfig {
|
||||||
cfg := network.TapConfig{
|
cfg := network.TapConfig{
|
||||||
Provider: c.Interface.Provider,
|
Provider: c.Interface.Provider,
|
||||||
Name: c.Interface.Name,
|
Name: c.Interface.Name,
|
||||||
@@ -164,7 +164,7 @@ type Worker struct {
|
|||||||
listener WorkerListener
|
listener WorkerListener
|
||||||
conWorker *SocketWorker
|
conWorker *SocketWorker
|
||||||
tapWorker *TapWorker
|
tapWorker *TapWorker
|
||||||
cfg *config.Point
|
cfg *config.Access
|
||||||
uuid string
|
uuid string
|
||||||
network *models.Network
|
network *models.Network
|
||||||
routes map[string]PrefixRule
|
routes map[string]PrefixRule
|
||||||
@@ -176,7 +176,7 @@ type Worker struct {
|
|||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWorker(cfg *config.Point) *Worker {
|
func NewWorker(cfg *config.Access) *Worker {
|
||||||
return &Worker{
|
return &Worker{
|
||||||
ifAddr: cfg.Interface.Address,
|
ifAddr: cfg.Interface.Address,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
@@ -247,7 +247,7 @@ func (w *Worker) SaveStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sts := client.Statistics()
|
sts := client.Statistics()
|
||||||
access := &schema.Point{
|
access := &schema.Access{
|
||||||
RxBytes: uint64(sts[libol.CsRecvOkay]),
|
RxBytes: uint64(sts[libol.CsRecvOkay]),
|
||||||
TxBytes: uint64(sts[libol.CsSendOkay]),
|
TxBytes: uint64(sts[libol.CsSendOkay]),
|
||||||
ErrPkt: uint64(sts[libol.CsSendError]),
|
ErrPkt: uint64(sts[libol.CsSendError]),
|
||||||
|
@@ -1,37 +1,38 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/luscis/openlan/pkg/cache"
|
"github.com/luscis/openlan/pkg/cache"
|
||||||
"github.com/luscis/openlan/pkg/models"
|
"github.com/luscis/openlan/pkg/models"
|
||||||
"github.com/luscis/openlan/pkg/schema"
|
"github.com/luscis/openlan/pkg/schema"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Point struct {
|
type Access struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Point) Router(router *mux.Router) {
|
func (h Access) Router(router *mux.Router) {
|
||||||
router.HandleFunc("/api/point", h.List).Methods("GET")
|
router.HandleFunc("/api/point", h.List).Methods("GET")
|
||||||
router.HandleFunc("/api/point/{id}", h.Get).Methods("GET")
|
router.HandleFunc("/api/point/{id}", h.Get).Methods("GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Point) List(w http.ResponseWriter, r *http.Request) {
|
func (h Access) List(w http.ResponseWriter, r *http.Request) {
|
||||||
points := make([]schema.Point, 0, 1024)
|
points := make([]schema.Access, 0, 1024)
|
||||||
for u := range cache.Point.List() {
|
for u := range cache.Access.List() {
|
||||||
if u == nil {
|
if u == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
points = append(points, models.NewPointSchema(u))
|
points = append(points, models.NewAccessSchema(u))
|
||||||
}
|
}
|
||||||
ResponseJson(w, points)
|
ResponseJson(w, points)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Point) Get(w http.ResponseWriter, r *http.Request) {
|
func (h Access) Get(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
point := cache.Point.Get(vars["id"])
|
point := cache.Access.Get(vars["id"])
|
||||||
if point != nil {
|
if point != nil {
|
||||||
ResponseJson(w, models.NewPointSchema(point))
|
ResponseJson(w, models.NewAccessSchema(point))
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, vars["id"], http.StatusNotFound)
|
http.Error(w, vars["id"], http.StatusNotFound)
|
||||||
}
|
}
|
@@ -6,7 +6,7 @@ func Add(router *mux.Router, switcher Switcher) {
|
|||||||
Link{Switcher: switcher}.Router(router)
|
Link{Switcher: switcher}.Router(router)
|
||||||
User{}.Router(router)
|
User{}.Router(router)
|
||||||
Neighbor{}.Router(router)
|
Neighbor{}.Router(router)
|
||||||
Point{}.Router(router)
|
Access{}.Router(router)
|
||||||
Network{Switcher: switcher}.Router(router)
|
Network{Switcher: switcher}.Router(router)
|
||||||
OnLine{}.Router(router)
|
OnLine{}.Router(router)
|
||||||
Lease{}.Router(router)
|
Lease{}.Router(router)
|
||||||
|
@@ -2,6 +2,7 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/luscis/openlan/pkg/cache"
|
"github.com/luscis/openlan/pkg/cache"
|
||||||
"github.com/luscis/openlan/pkg/libol"
|
"github.com/luscis/openlan/pkg/libol"
|
||||||
"github.com/luscis/openlan/pkg/models"
|
"github.com/luscis/openlan/pkg/models"
|
||||||
@@ -95,15 +96,15 @@ func (p *Access) onAuth(client libol.SocketClient, user *models.User) error {
|
|||||||
}
|
}
|
||||||
out.Info("Access.onAuth: on >>> %s <<<", dev.Name())
|
out.Info("Access.onAuth: on >>> %s <<<", dev.Name())
|
||||||
proto := p.master.Protocol()
|
proto := p.master.Protocol()
|
||||||
m := models.NewPoint(client, dev, proto)
|
m := models.NewAccess(client, dev, proto)
|
||||||
m.SetUser(user)
|
m.SetUser(user)
|
||||||
// free point has same uuid.
|
// free point has same uuid.
|
||||||
if om := cache.Point.GetByUUID(m.UUID); om != nil {
|
if om := cache.Access.GetByUUID(m.UUID); om != nil {
|
||||||
out.Info("Access.onAuth: OffClient %s", om.Client)
|
out.Info("Access.onAuth: OffClient %s", om.Client)
|
||||||
p.master.OffClient(om.Client)
|
p.master.OffClient(om.Client)
|
||||||
}
|
}
|
||||||
client.SetPrivate(m)
|
client.SetPrivate(m)
|
||||||
cache.Point.Add(m)
|
cache.Access.Add(m)
|
||||||
libol.Go(func() {
|
libol.Go(func() {
|
||||||
p.master.ReadTap(dev, func(f *libol.FrameMessage) error {
|
p.master.ReadTap(dev, func(f *libol.FrameMessage) error {
|
||||||
if err := client.WriteMsg(f); err != nil {
|
if err := client.WriteMsg(f); err != nil {
|
||||||
|
@@ -66,7 +66,7 @@ func (r *Request) onNeighbor(client libol.SocketClient, data []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func findLease(ifAddr string, p *models.Point) *schema.Lease {
|
func findLease(ifAddr string, p *models.Access) *schema.Lease {
|
||||||
alias := p.Alias
|
alias := p.Alias
|
||||||
network := p.Network
|
network := p.Network
|
||||||
lease := cache.Network.GetLease(alias, network) // try by alias firstly
|
lease := cache.Network.GetLease(alias, network) // try by alias firstly
|
||||||
@@ -116,7 +116,7 @@ func (r *Request) onIpAddr(client libol.SocketClient, data []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
out.Cmd("Request.onIpAddr: find %s", n)
|
out.Cmd("Request.onIpAddr: find %s", n)
|
||||||
p := cache.Point.Get(client.String())
|
p := cache.Access.Get(client.String())
|
||||||
if p == nil {
|
if p == nil {
|
||||||
out.Error("Request.onIpAddr: point notFound")
|
out.Error("Request.onIpAddr: point notFound")
|
||||||
return
|
return
|
||||||
|
28
pkg/cache/point.go → pkg/cache/access.go
vendored
28
pkg/cache/point.go → pkg/cache/access.go
vendored
@@ -5,51 +5,51 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/models"
|
"github.com/luscis/openlan/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type point struct {
|
type access struct {
|
||||||
Clients *libol.SafeStrMap
|
Clients *libol.SafeStrMap
|
||||||
UUIDAddr *libol.SafeStrStr
|
UUIDAddr *libol.SafeStrStr
|
||||||
AddrUUID *libol.SafeStrStr
|
AddrUUID *libol.SafeStrStr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *point) Init(size int) {
|
func (p *access) Init(size int) {
|
||||||
p.Clients = libol.NewSafeStrMap(size)
|
p.Clients = libol.NewSafeStrMap(size)
|
||||||
p.UUIDAddr = libol.NewSafeStrStr(size)
|
p.UUIDAddr = libol.NewSafeStrStr(size)
|
||||||
p.AddrUUID = libol.NewSafeStrStr(size)
|
p.AddrUUID = libol.NewSafeStrStr(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *point) Add(m *models.Point) {
|
func (p *access) Add(m *models.Access) {
|
||||||
_ = p.UUIDAddr.Reset(m.UUID, m.Client.String())
|
_ = p.UUIDAddr.Reset(m.UUID, m.Client.String())
|
||||||
_ = p.AddrUUID.Set(m.Client.String(), m.UUID)
|
_ = p.AddrUUID.Set(m.Client.String(), m.UUID)
|
||||||
_ = p.Clients.Set(m.Client.String(), m)
|
_ = p.Clients.Set(m.Client.String(), m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *point) Get(addr string) *models.Point {
|
func (p *access) Get(addr string) *models.Access {
|
||||||
if v := p.Clients.Get(addr); v != nil {
|
if v := p.Clients.Get(addr); v != nil {
|
||||||
m := v.(*models.Point)
|
m := v.(*models.Access)
|
||||||
m.Update()
|
m.Update()
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *point) GetByUUID(uuid string) *models.Point {
|
func (p *access) GetByUUID(uuid string) *models.Access {
|
||||||
if addr := p.GetAddr(uuid); addr != "" {
|
if addr := p.GetAddr(uuid); addr != "" {
|
||||||
return p.Get(addr)
|
return p.Get(addr)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *point) GetUUID(addr string) string {
|
func (p *access) GetUUID(addr string) string {
|
||||||
return p.AddrUUID.Get(addr)
|
return p.AddrUUID.Get(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *point) GetAddr(uuid string) string {
|
func (p *access) GetAddr(uuid string) string {
|
||||||
return p.UUIDAddr.Get(uuid)
|
return p.UUIDAddr.Get(uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *point) Del(addr string) {
|
func (p *access) Del(addr string) {
|
||||||
if v := p.Clients.Get(addr); v != nil {
|
if v := p.Clients.Get(addr); v != nil {
|
||||||
m := v.(*models.Point)
|
m := v.(*models.Access)
|
||||||
if m.Device != nil {
|
if m.Device != nil {
|
||||||
_ = m.Device.Close()
|
_ = m.Device.Close()
|
||||||
}
|
}
|
||||||
@@ -61,12 +61,12 @@ func (p *point) Del(addr string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *point) List() <-chan *models.Point {
|
func (p *access) List() <-chan *models.Access {
|
||||||
c := make(chan *models.Point, 128)
|
c := make(chan *models.Access, 128)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
p.Clients.Iter(func(k string, v interface{}) {
|
p.Clients.Iter(func(k string, v interface{}) {
|
||||||
if m, ok := v.(*models.Point); ok {
|
if m, ok := v.(*models.Access); ok {
|
||||||
m.Update()
|
m.Update()
|
||||||
c <- m
|
c <- m
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ func (p *point) List() <-chan *models.Point {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
var Point = point{
|
var Access = access{
|
||||||
Clients: libol.NewSafeStrMap(1024),
|
Clients: libol.NewSafeStrMap(1024),
|
||||||
UUIDAddr: libol.NewSafeStrStr(1024),
|
UUIDAddr: libol.NewSafeStrStr(1024),
|
||||||
AddrUUID: libol.NewSafeStrStr(1024),
|
AddrUUID: libol.NewSafeStrStr(1024),
|
2
pkg/cache/store.go
vendored
2
pkg/cache/store.go
vendored
@@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Init(cfg *config.Perf) {
|
func Init(cfg *config.Perf) {
|
||||||
Point.Init(cfg.Point)
|
Access.Init(cfg.Access)
|
||||||
Link.Init(cfg.Link)
|
Link.Init(cfg.Link)
|
||||||
Neighbor.Init(cfg.Neighbor)
|
Neighbor.Init(cfg.Neighbor)
|
||||||
Online.Init(cfg.OnLine)
|
Online.Init(cfg.OnLine)
|
||||||
|
6
pkg/cache/store_test.go
vendored
6
pkg/cache/store_test.go
vendored
@@ -22,10 +22,10 @@ func TestInit(t *testing.T) {
|
|||||||
cfg := &config.Perf{}
|
cfg := &config.Perf{}
|
||||||
cfg.Correct()
|
cfg.Correct()
|
||||||
Init(cfg)
|
Init(cfg)
|
||||||
fmt.Println(Point)
|
fmt.Println(Access)
|
||||||
Point.Add(&models.Point{
|
Access.Add(&models.Access{
|
||||||
UUID: "fake",
|
UUID: "fake",
|
||||||
Client: &SocketClientMock{},
|
Client: &SocketClientMock{},
|
||||||
})
|
})
|
||||||
assert.Equal(t, 1, Point.Clients.Len(), "MUST be same")
|
assert.Equal(t, 1, Access.Clients.Len(), "MUST be same")
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@ type Interface struct {
|
|||||||
Cost int `json:"cost,omitempty"`
|
Cost int `json:"cost,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Point struct {
|
type Access struct {
|
||||||
File string `json:"file,omitempty"`
|
File string `json:"file,omitempty"`
|
||||||
Alias string `json:"alias,omitempty"`
|
Alias string `json:"alias,omitempty"`
|
||||||
Connection string `json:"connection"`
|
Connection string `json:"connection"`
|
||||||
@@ -49,27 +49,27 @@ func (i *Interface) Correct() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPoint() *Point {
|
func NewAccess() *Access {
|
||||||
p := &Point{RequestAddr: true}
|
p := &Access{RequestAddr: true}
|
||||||
p.Parse()
|
p.Parse()
|
||||||
p.Initialize()
|
p.Initialize()
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ap *Point) Parse() {
|
func (ap *Access) Parse() {
|
||||||
flag.StringVar(&ap.Alias, "alias", "", "Alias for this point")
|
flag.StringVar(&ap.Alias, "alias", "", "Alias for this Access")
|
||||||
flag.StringVar(&ap.Log.File, "log:file", "", "File log saved to")
|
flag.StringVar(&ap.Log.File, "log:file", "", "File log saved to")
|
||||||
flag.StringVar(&ap.Conf, "conf", "", "The configuration file")
|
flag.StringVar(&ap.Conf, "conf", "", "The configuration file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ap *Point) Id() string {
|
func (ap *Access) Id() string {
|
||||||
return ap.Connection + ":" + ap.Network
|
return ap.Connection + ":" + ap.Network
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ap *Point) Initialize() error {
|
func (ap *Access) Initialize() error {
|
||||||
if err := ap.Load(); err != nil {
|
if err := ap.Load(); err != nil {
|
||||||
libol.Warn("NewPoint.Initialize %s", err)
|
libol.Warn("NewAccess.Initialize %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ap.Correct()
|
ap.Correct()
|
||||||
@@ -77,7 +77,7 @@ func (ap *Point) Initialize() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ap *Point) Correct() {
|
func (ap *Access) Correct() {
|
||||||
if ap.Alias == "" {
|
if ap.Alias == "" {
|
||||||
ap.Alias = GetAlias()
|
ap.Alias = GetAlias()
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ func (ap *Point) Correct() {
|
|||||||
ap.Queue.Correct()
|
ap.Queue.Correct()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ap *Point) Load() error {
|
func (ap *Access) Load() error {
|
||||||
if err := libol.FileExist(ap.Conf); err == nil {
|
if err := libol.FileExist(ap.Conf); err == nil {
|
||||||
return libol.UnmarshalLoad(ap, ap.Conf)
|
return libol.UnmarshalLoad(ap, ap.Conf)
|
||||||
}
|
}
|
@@ -9,8 +9,8 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPointFlags(t *testing.T) {
|
func TestAccessFlags(t *testing.T) {
|
||||||
ap := Point{}
|
ap := Access{}
|
||||||
os.Args = []string{
|
os.Args = []string{
|
||||||
"app",
|
"app",
|
||||||
"-conf", "/etc/openlan/fake.json",
|
"-conf", "/etc/openlan/fake.json",
|
||||||
@@ -22,8 +22,8 @@ func TestPointFlags(t *testing.T) {
|
|||||||
assert.Equal(t, "/etc/openlan/fake.json", ap.Conf, "be the same.")
|
assert.Equal(t, "/etc/openlan/fake.json", ap.Conf, "be the same.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPoint(t *testing.T) {
|
func TestAccess(t *testing.T) {
|
||||||
ap := Point{
|
ap := Access{
|
||||||
Username: "user0@fake",
|
Username: "user0@fake",
|
||||||
}
|
}
|
||||||
ap.Correct()
|
ap.Correct()
|
@@ -16,7 +16,7 @@ type Network struct {
|
|||||||
Bridge *Bridge `json:"bridge,omitempty"`
|
Bridge *Bridge `json:"bridge,omitempty"`
|
||||||
Subnet *Subnet `json:"subnet,omitempty"`
|
Subnet *Subnet `json:"subnet,omitempty"`
|
||||||
OpenVPN *OpenVPN `json:"openvpn,omitempty"`
|
OpenVPN *OpenVPN `json:"openvpn,omitempty"`
|
||||||
Links []Point `json:"links,omitempty"`
|
Links []Access `json:"links,omitempty"`
|
||||||
Hosts []HostLease `json:"hosts,omitempty"`
|
Hosts []HostLease `json:"hosts,omitempty"`
|
||||||
Routes []PrefixRoute `json:"routes,omitempty"`
|
Routes []PrefixRoute `json:"routes,omitempty"`
|
||||||
Acl string `json:"acl,omitempty"`
|
Acl string `json:"acl,omitempty"`
|
||||||
|
@@ -236,11 +236,12 @@ func (p *Proxy) Save() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type NameProxy struct {
|
type NameProxy struct {
|
||||||
Conf string `json:"-" yaml:"-"`
|
Conf string `json:"-" yaml:"-"`
|
||||||
Listen string `json:"listen,omitempty"`
|
Listen string `json:"listen,omitempty"`
|
||||||
Nameto string `json:"nameto,omitempty" yaml:"nameto,omitempty"`
|
Nameto string `json:"nameto,omitempty" yaml:"nameto,omitempty"`
|
||||||
Metric int
|
Metric int `json:"metric,omitempty" yaml:"metric,omitempty"`
|
||||||
Backends ToForwards `json:"backends,omitempty" yaml:"backends,omitempty"`
|
Backends ToForwards `json:"backends,omitempty" yaml:"backends,omitempty"`
|
||||||
|
Access []*Access `json:"access,omitempty" yaml:"access,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *NameProxy) Initialize() error {
|
func (t *NameProxy) Initialize() error {
|
||||||
@@ -258,6 +259,10 @@ func (t *NameProxy) Correct() {
|
|||||||
if t.Metric == 0 {
|
if t.Metric == 0 {
|
||||||
t.Metric = 300
|
t.Metric = 300
|
||||||
}
|
}
|
||||||
|
for _, acc := range t.Access {
|
||||||
|
acc.RequestAddr = true
|
||||||
|
acc.Correct()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *NameProxy) Load() error {
|
func (t *NameProxy) Load() error {
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Perf struct {
|
type Perf struct {
|
||||||
Point int `json:"point"`
|
Access int `json:"access"`
|
||||||
Neighbor int `json:"neighbor"`
|
Neighbor int `json:"neighbor"`
|
||||||
OnLine int `json:"online"`
|
OnLine int `json:"online"`
|
||||||
Link int `json:"link"`
|
Link int `json:"link"`
|
||||||
@@ -20,8 +20,8 @@ type Perf struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Perf) Correct() {
|
func (p *Perf) Correct() {
|
||||||
if p.Point == 0 {
|
if p.Access == 0 {
|
||||||
p.Point = 64
|
p.Access = 64
|
||||||
}
|
}
|
||||||
if p.Neighbor == 0 {
|
if p.Neighbor == 0 {
|
||||||
p.Neighbor = 64
|
p.Neighbor = 64
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/network"
|
"github.com/luscis/openlan/pkg/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Point struct {
|
type Access struct {
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Alias string `json:"alias"`
|
Alias string `json:"alias"`
|
||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
@@ -20,8 +20,8 @@ type Point struct {
|
|||||||
System string `json:"system"`
|
System string `json:"system"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPoint(c libol.SocketClient, d network.Taper, proto string) (w *Point) {
|
func NewAccess(c libol.SocketClient, d network.Taper, proto string) (w *Access) {
|
||||||
return &Point{
|
return &Access{
|
||||||
Alias: "",
|
Alias: "",
|
||||||
Server: c.LocalAddr(),
|
Server: c.LocalAddr(),
|
||||||
Client: c,
|
Client: c,
|
||||||
@@ -30,7 +30,7 @@ func NewPoint(c libol.SocketClient, d network.Taper, proto string) (w *Point) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) Update() *Point {
|
func (p *Access) Update() *Access {
|
||||||
client := p.Client
|
client := p.Client
|
||||||
if client != nil {
|
if client != nil {
|
||||||
p.Uptime = client.UpTime()
|
p.Uptime = client.UpTime()
|
||||||
@@ -43,7 +43,7 @@ func (p *Point) Update() *Point {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) SetUser(user *User) {
|
func (p *Access) SetUser(user *User) {
|
||||||
p.User = user.Name
|
p.User = user.Name
|
||||||
p.UUID = user.UUID
|
p.UUID = user.UUID
|
||||||
if len(p.UUID) > 13 {
|
if len(p.UUID) > 13 {
|
@@ -12,12 +12,12 @@ type Link struct {
|
|||||||
StatusFile string
|
StatusFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Link) reload() *schema.Point {
|
func (l *Link) reload() *schema.Access {
|
||||||
status := &schema.Point{}
|
status := &schema.Access{}
|
||||||
_ = libol.UnmarshalLoad(status, l.StatusFile)
|
_ = libol.UnmarshalLoad(status, l.StatusFile)
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Link) Status() *schema.Point {
|
func (l *Link) Status() *schema.Access {
|
||||||
return l.reload()
|
return l.reload()
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/luscis/openlan/pkg/libol"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/luscis/openlan/pkg/libol"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Neighbor struct {
|
type Neighbor struct {
|
||||||
@@ -47,9 +48,9 @@ func (e *Neighbor) Update(client libol.SocketClient) {
|
|||||||
if private == nil {
|
if private == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if point, ok := private.(*Point); ok {
|
if acc, ok := private.(*Access); ok {
|
||||||
e.Network = point.Network
|
e.Network = acc.Network
|
||||||
e.Device = point.IfName
|
e.Device = acc.IfName
|
||||||
e.Client = client.String()
|
e.Client = client.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,10 +5,10 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/schema"
|
"github.com/luscis/openlan/pkg/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewPointSchema(p *Point) schema.Point {
|
func NewAccessSchema(p *Access) schema.Access {
|
||||||
client, dev := p.Client, p.Device
|
client, dev := p.Client, p.Device
|
||||||
sts := client.Statistics()
|
sts := client.Statistics()
|
||||||
return schema.Point{
|
return schema.Access{
|
||||||
Uptime: p.Uptime,
|
Uptime: p.Uptime,
|
||||||
UUID: p.UUID,
|
UUID: p.UUID,
|
||||||
Alias: p.Alias,
|
Alias: p.Alias,
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/luscis/openlan/pkg/access"
|
||||||
"github.com/luscis/openlan/pkg/config"
|
"github.com/luscis/openlan/pkg/config"
|
||||||
"github.com/luscis/openlan/pkg/libol"
|
"github.com/luscis/openlan/pkg/libol"
|
||||||
"github.com/luscis/openlan/pkg/network"
|
"github.com/luscis/openlan/pkg/network"
|
||||||
@@ -20,19 +21,27 @@ type NameProxy struct {
|
|||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
names map[string]string
|
names map[string]string
|
||||||
addrs map[string]string
|
addrs map[string]string
|
||||||
|
access []*access.Access
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNameProxy(cfg *config.NameProxy) *NameProxy {
|
func NewNameProxy(cfg *config.NameProxy) *NameProxy {
|
||||||
return &NameProxy{
|
n := &NameProxy{
|
||||||
listen: cfg.Listen,
|
listen: cfg.Listen,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
out: libol.NewSubLogger(cfg.Listen),
|
out: libol.NewSubLogger(cfg.Listen),
|
||||||
names: make(map[string]string),
|
names: make(map[string]string),
|
||||||
addrs: make(map[string]string),
|
addrs: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
n.Initialize()
|
||||||
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NameProxy) Initialize() {
|
func (n *NameProxy) Initialize() {
|
||||||
|
for _, cfg := range n.cfg.Access {
|
||||||
|
acc := access.NewAccess(cfg)
|
||||||
|
acc.Initialize()
|
||||||
|
n.access = append(n.access, acc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NameProxy) Forward(name, addr, nexthop string) {
|
func (n *NameProxy) Forward(name, addr, nexthop string) {
|
||||||
@@ -130,14 +139,22 @@ func (n *NameProxy) handleDNS(conn dns.ResponseWriter, r *dns.Msg) {
|
|||||||
func (n *NameProxy) Start() {
|
func (n *NameProxy) Start() {
|
||||||
dns.HandleFunc(".", n.handleDNS)
|
dns.HandleFunc(".", n.handleDNS)
|
||||||
n.server = &dns.Server{Addr: n.listen, Net: "udp"}
|
n.server = &dns.Server{Addr: n.listen, Net: "udp"}
|
||||||
|
|
||||||
n.out.Info("NameProxy.StartDNS on %s", n.listen)
|
n.out.Info("NameProxy.StartDNS on %s", n.listen)
|
||||||
|
|
||||||
|
for _, acc := range n.access {
|
||||||
|
libol.Go(acc.Start)
|
||||||
|
}
|
||||||
if err := n.server.ListenAndServe(); err != nil {
|
if err := n.server.ListenAndServe(); err != nil {
|
||||||
n.out.Error("NameProxy.StartDNS server: %v", err)
|
n.out.Error("NameProxy.StartDNS server: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NameProxy) Stop() {
|
func (n *NameProxy) Stop() {
|
||||||
|
for _, acc := range n.access {
|
||||||
|
acc.Stop()
|
||||||
|
}
|
||||||
|
n.access = nil
|
||||||
if n.server != nil {
|
if n.server != nil {
|
||||||
n.server.Shutdown()
|
n.server.Shutdown()
|
||||||
n.server = nil
|
n.server = nil
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package schema
|
package schema
|
||||||
|
|
||||||
type Point struct {
|
type Access struct {
|
||||||
Uptime int64 `json:"uptime"`
|
Uptime int64 `json:"uptime"`
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
@@ -3,7 +3,7 @@ package schema
|
|||||||
type Index struct {
|
type Index struct {
|
||||||
Version Version `json:"version"`
|
Version Version `json:"version"`
|
||||||
Worker Worker `json:"worker"`
|
Worker Worker `json:"worker"`
|
||||||
Points []Point `json:"points"`
|
Access []Access `json:"access"`
|
||||||
Links []Link `json:"links"`
|
Links []Link `json:"links"`
|
||||||
Neighbors []Neighbor `json:"neighbors"`
|
Neighbors []Neighbor `json:"neighbors"`
|
||||||
OnLines []OnLine `json:"online"`
|
OnLines []OnLine `json:"online"`
|
||||||
|
@@ -246,16 +246,16 @@ func (h *Http) getIndex(body *schema.Index) *schema.Index {
|
|||||||
body.Version = schema.NewVersionSchema()
|
body.Version = schema.NewVersionSchema()
|
||||||
body.Worker = api.NewWorkerSchema(h.switcher)
|
body.Worker = api.NewWorkerSchema(h.switcher)
|
||||||
|
|
||||||
// display accessed point.
|
// display accessed Access.
|
||||||
for p := range cache.Point.List() {
|
for p := range cache.Access.List() {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
body.Points = append(body.Points, models.NewPointSchema(p))
|
body.Access = append(body.Access, models.NewAccessSchema(p))
|
||||||
}
|
}
|
||||||
sort.SliceStable(body.Points, func(i, j int) bool {
|
sort.SliceStable(body.Access, func(i, j int) bool {
|
||||||
ii := body.Points[i]
|
ii := body.Access[i]
|
||||||
jj := body.Points[j]
|
jj := body.Access[j]
|
||||||
return ii.Network+ii.Remote > jj.Network+jj.Remote
|
return ii.Network+ii.Remote > jj.Network+jj.Remote
|
||||||
})
|
})
|
||||||
// display neighbor.
|
// display neighbor.
|
||||||
|
@@ -19,12 +19,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Link struct {
|
type Link struct {
|
||||||
cfg *co.Point
|
cfg *co.Access
|
||||||
out *libol.SubLogger
|
out *libol.SubLogger
|
||||||
uuid string
|
uuid string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLink(cfg *co.Point) *Link {
|
func NewLink(cfg *co.Access) *Link {
|
||||||
uuid := libol.GenString(13)
|
uuid := libol.GenString(13)
|
||||||
return &Link{
|
return &Link{
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
@@ -50,7 +50,7 @@ func (l *Link) Initialize() {
|
|||||||
_ = libol.MarshalSave(l.cfg, file, true)
|
_ = libol.MarshalSave(l.cfg, file, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Link) Conf() *co.Point {
|
func (l *Link) Conf() *co.Access {
|
||||||
return l.cfg
|
return l.cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -207,7 +207,7 @@ func (w *WorkerImpl) addOutput(bridge string, port *co.Output) {
|
|||||||
port.Link = cn.Taps.GenName()
|
port.Link = cn.Taps.GenName()
|
||||||
name, pass := SplitCombined(port.Secret)
|
name, pass := SplitCombined(port.Secret)
|
||||||
algo, secret := SplitCombined(port.Crypt)
|
algo, secret := SplitCombined(port.Crypt)
|
||||||
ac := co.Point{
|
ac := co.Access{
|
||||||
Alias: w.cfg.Alias,
|
Alias: w.cfg.Alias,
|
||||||
Network: w.cfg.Name,
|
Network: w.cfg.Name,
|
||||||
RequestAddr: false,
|
RequestAddr: false,
|
||||||
|
@@ -174,7 +174,7 @@ func (w *OpenLANWorker) UpTime() int64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *OpenLANWorker) AddLink(c co.Point) {
|
func (w *OpenLANWorker) AddLink(c co.Access) {
|
||||||
br := w.cfg.Bridge
|
br := w.cfg.Bridge
|
||||||
|
|
||||||
c.Alias = w.alias
|
c.Alias = w.alias
|
||||||
|
@@ -189,7 +189,7 @@ func (v *Switch) preNetwork() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *Switch) preApplication() {
|
func (v *Switch) preApplication() {
|
||||||
// Append accessed auth for point
|
// Append accessed auth for Access
|
||||||
v.apps.Auth = app.NewAccess(v)
|
v.apps.Auth = app.NewAccess(v)
|
||||||
v.hooks = append(v.hooks, v.apps.Auth.OnFrame)
|
v.hooks = append(v.hooks, v.apps.Auth.OnFrame)
|
||||||
// Append request process
|
// Append request process
|
||||||
@@ -331,14 +331,14 @@ func (v *Switch) SignIn(client libol.SocketClient) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func client2Point(client libol.SocketClient) (*models.Point, error) {
|
func client2Access(client libol.SocketClient) (*models.Access, error) {
|
||||||
addr := client.RemoteAddr()
|
addr := client.RemoteAddr()
|
||||||
if private := client.Private(); private == nil {
|
if private := client.Private(); private == nil {
|
||||||
return nil, libol.NewErr("point %s notFound.", addr)
|
return nil, libol.NewErr("Access %s notFound.", addr)
|
||||||
} else {
|
} else {
|
||||||
obj, ok := private.(*models.Point)
|
obj, ok := private.(*models.Access)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, libol.NewErr("point %s notRight.", addr)
|
return nil, libol.NewErr("Access %s notRight.", addr)
|
||||||
}
|
}
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
@@ -353,7 +353,7 @@ func (v *Switch) ReadClient(client libol.SocketClient, frame *libol.FrameMessage
|
|||||||
if err := v.onFrame(client, frame); err != nil {
|
if err := v.onFrame(client, frame); err != nil {
|
||||||
v.out.Debug("Switch.ReadClient: %s dropping by %s", addr, err)
|
v.out.Debug("Switch.ReadClient: %s dropping by %s", addr, err)
|
||||||
if frame.Action() == libol.PingReq {
|
if frame.Action() == libol.PingReq {
|
||||||
// send sign message to point require login.
|
// send sign message to Access require login.
|
||||||
_ = v.SignIn(client)
|
_ = v.SignIn(client)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -362,7 +362,7 @@ func (v *Switch) ReadClient(client libol.SocketClient, frame *libol.FrameMessage
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// process ethernet frame message.
|
// process ethernet frame message.
|
||||||
obj, err := client2Point(client)
|
obj, err := client2Access(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -380,10 +380,10 @@ func (v *Switch) ReadClient(client libol.SocketClient, frame *libol.FrameMessage
|
|||||||
func (v *Switch) OnClose(client libol.SocketClient) error {
|
func (v *Switch) OnClose(client libol.SocketClient) error {
|
||||||
addr := client.RemoteAddr()
|
addr := client.RemoteAddr()
|
||||||
v.out.Info("Switch.OnClose: %s", addr)
|
v.out.Info("Switch.OnClose: %s", addr)
|
||||||
if obj, err := client2Point(client); err == nil {
|
if obj, err := client2Access(client); err == nil {
|
||||||
cache.Network.DelLease(obj.Alias, obj.Network)
|
cache.Network.DelLease(obj.Alias, obj.Network)
|
||||||
}
|
}
|
||||||
cache.Point.Del(addr)
|
cache.Access.Del(addr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,9 +428,9 @@ func (v *Switch) Stop() {
|
|||||||
}
|
}
|
||||||
w.Stop()
|
w.Stop()
|
||||||
}
|
}
|
||||||
v.out.Info("Switch.Stop left points")
|
v.out.Info("Switch.Stop left Accesss")
|
||||||
// notify leave to point.
|
// notify leave to Access.
|
||||||
for p := range cache.Point.List() {
|
for p := range cache.Access.List() {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user