logging method modify
This commit is contained in:
parent
859a0c9264
commit
1d7d80f236
22
dhcp/dhcp.go
22
dhcp/dhcp.go
|
@ -46,7 +46,7 @@ type dhcpDiscover struct {
|
||||||
func DiscoverDHCP() {
|
func DiscoverDHCP() {
|
||||||
err := sendDHCPDiscovery()
|
err := sendDHCPDiscovery()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: DHCP Matcher %v", err))
|
logging.Logger().Errorf("Discovery: DHCP Matcher %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
recvDHCPOffer()
|
recvDHCPOffer()
|
||||||
|
@ -101,23 +101,23 @@ func recvDHCPOffer() {
|
||||||
Port: 68,
|
Port: 68,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: DHCP Matcher %v", err))
|
logging.Logger().Errorf("Discovery: DHCP Matcher %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = socket.SetDeadline(time.Now().Add(3 * time.Second))
|
err = socket.SetDeadline(time.Now().Add(3 * time.Second))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: DHCP Matcher %v", err))
|
logging.Logger().Errorf("Discovery: DHCP Matcher %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, 4096)
|
buf := make([]byte, 4096)
|
||||||
n, _, err := socket.ReadFromUDP(buf)
|
n, _, err := socket.ReadFromUDP(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: DHCP Matcher %v", err))
|
logging.Logger().Errorf("Discovery: DHCP Matcher %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: DHCP Matcher has no DHCP offer."))
|
logging.Logger().Errorf("Discovery: DHCP Matcher has no DHCP offer.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,11 +126,11 @@ func recvDHCPOffer() {
|
||||||
reader := new(bytes.Buffer)
|
reader := new(bytes.Buffer)
|
||||||
reader.Write(buf)
|
reader.Write(buf)
|
||||||
if err := binary.Read(reader, binary.BigEndian, &offer); err != nil {
|
if err := binary.Read(reader, binary.BigEndian, &offer); err != nil {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: DHCP Matcher %v", err))
|
logging.Logger().Errorf("Discovery: DHCP Matcher %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if offer.MagicCookie != MAGIC_COOKIE {
|
if offer.MagicCookie != MAGIC_COOKIE {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: DHCP Matcher is not a DHCP packet."))
|
logging.Logger().Errorf("Discovery: DHCP Matcher is not a DHCP packet.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,12 +143,12 @@ func recvDHCPOffer() {
|
||||||
|
|
||||||
if v == OPT_CODE_SUBNET_MASK && r.Next(1)[0] == 4 {
|
if v == OPT_CODE_SUBNET_MASK && r.Next(1)[0] == 4 {
|
||||||
ipStr := byteToIpString(r.Next(4))
|
ipStr := byteToIpString(r.Next(4))
|
||||||
logging.Logger().Info(fmt.Sprintf("Discovery: DHCP Matcher SUBNET MASK: %s", ipStr))
|
logging.Logger().Infof("Discovery: DHCP Matcher SUBNET MASK: %s", ipStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v == OPT_CODE_ROUTER && r.Next(1)[0] == 4 {
|
if v == OPT_CODE_ROUTER && r.Next(1)[0] == 4 {
|
||||||
ipStr := byteToIpString(r.Next(4))
|
ipStr := byteToIpString(r.Next(4))
|
||||||
logging.Logger().Info(fmt.Sprintf("Discovery: DHCP Matcher ROUTER: %s", ipStr))
|
logging.Logger().Infof("Discovery: DHCP Matcher ROUTER: %s", ipStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v == OPT_CODE_DNS {
|
if v == OPT_CODE_DNS {
|
||||||
|
@ -161,12 +161,12 @@ func recvDHCPOffer() {
|
||||||
ipStr = byteToIpString(r.Next(4))
|
ipStr = byteToIpString(r.Next(4))
|
||||||
dns = append(dns, ipStr)
|
dns = append(dns, ipStr)
|
||||||
}
|
}
|
||||||
logging.Logger().Info(fmt.Sprintf("Discovery: DHCP Matcher DNS: %s", dns))
|
logging.Logger().Infof("Discovery: DHCP Matcher DNS: %s", dns)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v == OPT_CODE_SERVER_IDENTIFIER && r.Next(1)[0] == 4 {
|
if v == OPT_CODE_SERVER_IDENTIFIER && r.Next(1)[0] == 4 {
|
||||||
ipStr := byteToIpString(r.Next(4))
|
ipStr := byteToIpString(r.Next(4))
|
||||||
logging.Logger().Info(fmt.Sprintf("Discovery: DHCP Matcher DHCP SERVER: %s", ipStr))
|
logging.Logger().Infof("Discovery: DHCP Matcher DHCP SERVER: %s", ipStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logging.Logger().Sync()
|
logging.Logger().Sync()
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (ftp *FTPMatcher) Match(info cnsm.MatchInfo, index int, packet *cnsm.Packet
|
||||||
result := false
|
result := false
|
||||||
|
|
||||||
if packet == nil || packet.Buffer == nil || packet.Len == 0 {
|
if packet == nil || packet.Buffer == nil || packet.Len == 0 {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: FTP Matcher Packet nil"))
|
logging.Logger().Errorf("Discovery: FTP Matcher Packet nil")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ func (ftp *FTPMatcher) Match(info cnsm.MatchInfo, index int, packet *cnsm.Packet
|
||||||
if isfs && err == nil {
|
if isfs && err == nil {
|
||||||
ftp.isFtps = isfs
|
ftp.isFtps = isfs
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
logging.Logger().Warn(fmt.Sprintf("Discovery: FTP Matcher Check Error %v", err))
|
logging.Logger().Warnf("Discovery: FTP Matcher Check Error %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,12 @@ func (fs *FTPS) quit() (err error) {
|
||||||
|
|
||||||
func (fs *FTPS) cmd(expects string, cmd string) (line string, err error) {
|
func (fs *FTPS) cmd(expects string, cmd string) (line string, err error) {
|
||||||
if err = fs.send(cmd); err != nil {
|
if err = fs.send(cmd); err != nil {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: FTPS Matcher cmd send error %v", err))
|
logging.Logger().Errorf("Discovery: FTPS Matcher cmd send error %v", err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if line, err = fs.receive(); err != nil {
|
if line, err = fs.receive(); err != nil {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: FTPS Matcher cmd receive error %v", err))
|
logging.Logger().Errorf("Discovery: FTPS Matcher cmd receive error %v", err)
|
||||||
return line, err
|
return line, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ func (fs *FTPS) NewFTPSConnect(addr string) (*FTPS, error) {
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
|
|
||||||
if conn, err = net.Dial("tcp", addr); err != nil {
|
if conn, err = net.Dial("tcp", addr); err != nil {
|
||||||
logging.Logger().Error(fmt.Sprintf("Discovery: FTPS Matcher Socket Fail %v", err))
|
logging.Logger().Errorf("Discovery: FTPS Matcher Socket Fail %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user