update... work pending
This commit is contained in:
@@ -53,7 +53,7 @@ func GetTunnel(cfg *conf.Tunnel, debug bool) (tun *Tunnel, err error) {
|
||||
|
||||
tun = tuns.Tunnels[0]
|
||||
tun.client = client
|
||||
tun.tunCfg = cfg
|
||||
tun.TunCfg = cfg
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,6 +9,16 @@ import (
|
||||
"r00t2.io/clientinfo/server"
|
||||
)
|
||||
|
||||
// Has48 returns true if this Tunnel has a /48 assigned.
|
||||
func (t *Tunnel) Has48() (has48 bool) {
|
||||
|
||||
if t.Routed48 != nil {
|
||||
has48 = true
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Update checks the current (or explicit) client IPv4 address, compares it against the Tunnel's configuration,
|
||||
and updates itself on change.
|
||||
@@ -20,10 +30,9 @@ func (t *Tunnel) Update() (updated bool, err error) {
|
||||
var req *resty.Request
|
||||
var targetIp net.IP
|
||||
var respStrs []string
|
||||
var newTun *Tunnel = new(Tunnel)
|
||||
|
||||
if t.tunCfg.ExplicitAddr != nil {
|
||||
targetIp = *t.tunCfg.ExplicitAddr
|
||||
if t.TunCfg.ExplicitAddr != nil {
|
||||
targetIp = *t.TunCfg.ExplicitAddr
|
||||
} else {
|
||||
// Fetch the current client IP.
|
||||
// Teeechnically we don't need to do this, as it by default uses client IP, but we wanna be as considerate as we can.
|
||||
@@ -45,8 +54,8 @@ func (t *Tunnel) Update() (updated bool, err error) {
|
||||
if !t.ClientIPv4.Equal(targetIp) {
|
||||
// It's different, so update.
|
||||
req = t.client.R()
|
||||
req.SetBasicAuth(*t.tunCfg.Username, t.tunCfg.UpdateKey)
|
||||
req.SetQueryParam(updateTidParam, fmt.Sprintf("%d", t.tunCfg.TunnelID))
|
||||
req.SetBasicAuth(*t.TunCfg.Username, t.TunCfg.UpdateKey)
|
||||
req.SetQueryParam(updateTidParam, fmt.Sprintf("%d", t.TunCfg.TunnelID))
|
||||
req.SetQueryParam(updateIpParam, targetIp.To4().String())
|
||||
|
||||
if resp, err = req.Get(updateBaseUrl); err != nil {
|
||||
@@ -59,20 +68,17 @@ func (t *Tunnel) Update() (updated bool, err error) {
|
||||
respStrs = strings.Fields(resp.String())
|
||||
if respStrs == nil || len(respStrs) == 0 {
|
||||
// I... don't know what would result in this, but let's assume it succeeded.
|
||||
if newTun, err = GetTunnel(t.tunCfg, t.client.Debug); err != nil {
|
||||
return
|
||||
}
|
||||
updated = true
|
||||
*t = *newTun
|
||||
|
||||
return
|
||||
}
|
||||
switch len(respStrs) {
|
||||
case 1:
|
||||
switch respStrs[0] {
|
||||
case "abuse":
|
||||
if respStrs[0] == "abuse" {
|
||||
err = ErrHERateLimit
|
||||
return
|
||||
}
|
||||
case 2:
|
||||
switch respStrs[0] {
|
||||
case "nochg":
|
||||
// No update; existing value is the same
|
||||
return
|
||||
@@ -89,9 +95,7 @@ func (t *Tunnel) Update() (updated bool, err error) {
|
||||
return
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@@ -17,33 +17,55 @@ import (
|
||||
*/
|
||||
type TunPrefix netip.Prefix
|
||||
|
||||
// TunnelList is what's returned from the tunnelbroker.net API, regardless if a specific tunnel ID is specified or not.
|
||||
type TunnelList struct {
|
||||
XMLName xml.Name `json:"-" xml:"tunnels" yaml:"-"`
|
||||
XMLName xml.Name `json:"-" xml:"tunnels" yaml:"-"`
|
||||
// Tunnels should only contain a single Tunnel if a (valid) tunnel ID was specified.
|
||||
Tunnels []*Tunnel `json:"tunnels" xml:"tunnel" yaml:"Tunnels"`
|
||||
}
|
||||
|
||||
// Tunnel is a single tunnel configuration as returned from the tunnelbroker.net API.
|
||||
type Tunnel struct {
|
||||
XMLName xml.Name `json:"-" xml:"tunnel" yaml:"-"`
|
||||
ID uint `json:"id" xml:"id,attr" yaml:"ID" db:"tun_id"`
|
||||
Description string `json:"desc" xml:"description" yaml:"Description" db:"desc"`
|
||||
ServerIPv4 net.IP `json:"tgt_v4" xml:"serverv4" yaml:"IPv4 Tunnel Target" db:"server_v4"`
|
||||
ClientIPv4 net.IP `json:"client_v4" xml:"clientv4" yaml:"Configured IPv4 Client Address" db:"current_client_v4"`
|
||||
ServerIPv6 net.IP `json:"server_v6" xml:"serverv6" yaml:"IPv6 Endpoint" db:"tunnel_server_v6"`
|
||||
ClientIPv6 net.IP `json:"client_v6" xml:"clientv6" yaml:"IPv6 Tunnel Client Address" db:"tunnel_client_v6"`
|
||||
Routed64 TunPrefix `json:"routed_64" xml:"routed64" yaml:"Routed /64" db:"prefix_64"`
|
||||
Routed48 *TunPrefix `json:"routed_48,omitempty" xml:"routed48,omitempty" yaml:"Routed /48,omitempty" db:"prefix_48"`
|
||||
RDNS1 *string `json:"rdns_1,omitempty" xml:"rdns1,omitempty" yaml:"RDNS #1,omitempty" db:"rdns_1"`
|
||||
RDNS2 *string `json:"rdns_2,omitempty" xml:"rdns2,omitempty" yaml:"RDNS #2,omitempty" db:"rdns_2"`
|
||||
RDNS3 *string `json:"rdns_3,omitempty" xml:"rdns3,omitempty" yaml:"RDNS #3,omitempty" db:"rdns_3"`
|
||||
RDNS4 *string `json:"rdns_4,omitempty" xml:"rdns4,omitempty" yaml:"RDNS #4,omitempty" db:"rdns_4"`
|
||||
RDNS5 *string `json:"rdns_5,omitempty" xml:"rdns5,omitempty" yaml:"RDNS #5,omitempty" db:"rdns_5"`
|
||||
tunCfg *conf.Tunnel
|
||||
client *resty.Client
|
||||
XMLName xml.Name `json:"-" xml:"tunnel" yaml:"-"`
|
||||
// ID should correspond with a conf.Tunnel.ID.
|
||||
ID uint `json:"id" xml:"id,attr" yaml:"ID" db:"tun_id"`
|
||||
// Description is generally thought of more as a "friendly name" for the tunnel.
|
||||
Description string `json:"desc" xml:"description" yaml:"Description" db:"desc"`
|
||||
// ServerIPv4 is the "tunnel server"; the SIT client should use this as the server.
|
||||
ServerIPv4 net.IP `json:"tgt_v4" xml:"serverv4" yaml:"IPv4 Tunnel Target" db:"server_v4"`
|
||||
// ClientIPv4 is the *currently configured* "authorized client IP"; this should be the WAN-routable address of the client end of the SIT.
|
||||
ClientIPv4 net.IP `json:"client_v4" xml:"clientv4" yaml:"Configured IPv4 Client Address" db:"current_client_v4"`
|
||||
// ServerIPv6 is the gateway end that your SIT address (ClientIPv6) "peers" with.
|
||||
ServerIPv6 net.IP `json:"server_v6" xml:"serverv6" yaml:"IPv6 Endpoint" db:"tunnel_server_v6"`
|
||||
// ClientIPv6 is the address that should be assigned on your server's SIT interface.
|
||||
ClientIPv6 net.IP `json:"client_v6" xml:"clientv6" yaml:"IPv6 Tunnel Client Address" db:"tunnel_client_v6"`
|
||||
// Routed64 is the IPv6 prefix that gets routed to ClientIPv6. All tunnels have this.
|
||||
Routed64 TunPrefix `json:"routed_64" xml:"routed64" yaml:"Routed /64" db:"prefix_64"`
|
||||
// Routed48 may or may not be present, and only available after a certain level of HE certification has been completed and it has been allocated in the web UI.
|
||||
Routed48 *TunPrefix `json:"routed_48,omitempty" xml:"routed48,omitempty" yaml:"Routed /48,omitempty" db:"prefix_48"`
|
||||
// RDNS1 is the first RDNS you have specified for the tunnel, if any.
|
||||
RDNS1 *string `json:"rdns_1,omitempty" xml:"rdns1,omitempty" yaml:"RDNS #1,omitempty" db:"rdns_1"`
|
||||
// RDNS2 is the second RDNS you have specified for the tunnel, if any.
|
||||
RDNS2 *string `json:"rdns_2,omitempty" xml:"rdns2,omitempty" yaml:"RDNS #2,omitempty" db:"rdns_2"`
|
||||
// RDNS3 is the third RDNS you have specified for the tunnel, if any.
|
||||
RDNS3 *string `json:"rdns_3,omitempty" xml:"rdns3,omitempty" yaml:"RDNS #3,omitempty" db:"rdns_3"`
|
||||
// RDNS4 is the fourth RDNS you have specified for the tunnel, if any.
|
||||
RDNS4 *string `json:"rdns_4,omitempty" xml:"rdns4,omitempty" yaml:"RDNS #4,omitempty" db:"rdns_4"`
|
||||
// RDNS5 is the fifth RDNS you have specified for the tunnel, if any.
|
||||
RDNS5 *string `json:"rdns_5,omitempty" xml:"rdns5,omitempty" yaml:"RDNS #5,omitempty" db:"rdns_5"`
|
||||
// TunCfg is the tunnel as defined in the local configuration file associated with this Tunnel.
|
||||
TunCfg *conf.Tunnel `json:"-" xml:"-" yaml:"-"`
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
// HTTPError is a handler for non-success HTTP(S) requests.
|
||||
type HTTPError struct {
|
||||
Code int `json:"code" xml:"code,attr" yaml:"Status Code"`
|
||||
CodeStr string `json:"code_str" xml:"code_str,attr" yaml:"Status Code (Detailed)"`
|
||||
Message *string `json:"message,omitempty" xml:",chardata" yaml:"Error Message,omitempty"`
|
||||
Resp *resty.Response `json:"-" xml:"-" yaml:"-"`
|
||||
// Code is the status code as reported by the server.
|
||||
Code int `json:"code" xml:"code,attr" yaml:"Status Code"`
|
||||
// CodeStr is a more human-friendly string. It includes Code.
|
||||
CodeStr string `json:"code_str" xml:"code_str,attr" yaml:"Status Code (Detailed)"`
|
||||
// Message is any message sent from the server in the response's body, if any.
|
||||
Message *string `json:"message,omitempty" xml:",chardata" yaml:"Error Message,omitempty"`
|
||||
// Resp is the actual response received.
|
||||
Resp *resty.Response `json:"-" xml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user