-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathladdr.go
113 lines (98 loc) · 2.11 KB
/
laddr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright 2016 Xiaomi Corporation. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*
* Authors: Yu Bo <[email protected]>
*/
package govs
import (
"fmt"
"strings"
)
type Vs_laddr_user struct {
Nic uint8
Addr Be32
}
type Vs_laddr_user_r struct {
Addr Be32
Conn_counts uint32
Port_conflict uint64
}
func Laddr_title() string {
return fmt.Sprintf(" %15s %8s %8s",
"Addr", "Conn_counts", "Port_conflict")
}
func (l Vs_laddr_user_r) String() string {
return fmt.Sprintf(" %15s %8d %8d",
l.Addr.String(),
l.Conn_counts, l.Port_conflict)
}
type Vs_list_laddrs_r struct {
Code int
Msg string
Laddrs []Vs_laddr_user_r
}
func (r Vs_list_laddrs_r) String() string {
var s string
if r.Code != 0 {
return fmt.Sprintf("%s:%s", Ecode(r.Code), r.Msg)
}
for _, laddr := range r.Laddrs {
s += fmt.Sprintf("%s\n", laddr)
}
return strings.TrimRight(s, "\n")
}
func Get_laddrs(o *CmdOptions) (*Vs_list_laddrs_r, error) {
var reply Vs_list_laddrs_r
args := Vs_list_q{
Cmd: VS_CMD_GET_LADDR,
Service: Vs_service_user{
Addr: o.Addr.Ip,
Port: o.Addr.Port,
Protocol: uint8(o.Protocol),
Number: o.Number,
},
}
err := client.Call("api", args, &reply)
return &reply, err
}
type Vs_laddr_q struct {
Cmd int
Service Vs_service_user
Laddr Vs_laddr_user
}
func Set_addladdr(o *CmdOptions) (*Vs_cmd_r, error) {
var reply Vs_cmd_r
args := Vs_laddr_q{
Cmd: VS_CMD_NEW_LADDR,
Service: Vs_service_user{
Protocol: uint8(o.Protocol),
Addr: o.Addr.Ip,
Port: o.Addr.Port,
},
Laddr: Vs_laddr_user{
Nic: uint8(o.Lnic),
Addr: o.Lip,
},
}
err := client.Call("api", args, &reply)
return &reply, err
}
func Set_delladdr(o *CmdOptions) (*Vs_cmd_r, error) {
var reply Vs_cmd_r
args := Vs_laddr_q{
Cmd: VS_CMD_DEL_LADDR,
Service: Vs_service_user{
Protocol: uint8(o.Protocol),
Addr: o.Addr.Ip,
Port: o.Addr.Port,
},
Laddr: Vs_laddr_user{
Nic: uint8(o.Lnic),
Addr: o.Lip,
},
}
err := client.Call("api", args, &reply)
return &reply, err
}