-
Notifications
You must be signed in to change notification settings - Fork 156
/
handlelookupparam.go
67 lines (56 loc) · 1.58 KB
/
handlelookupparam.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
// Copyright (c) 2017-2018 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
// Publish the IsZedmanager AppNetworkConfig and /etc/hosts
// XXX Should also look at the corresponding AppNetworkStatus and report
// any errors back as device errors to zedcloud.
package zedagent
import (
"bytes"
"net"
"github.com/lf-edge/eve/pkg/pillar/types"
)
const (
infraFileName = types.IdentityDirname + "/infra"
zedserverConfigFileName = types.TmpDirname + "/zedserverconfig"
)
func publishAppNetworkConfig(getconfigCtx *getconfigContext,
config types.AppNetworkConfig) {
key := config.Key()
log.Tracef("publishAppNetworkConfig %s", key)
pub := getconfigCtx.pubAppNetworkConfig
pub.Publish(key, config)
}
func unpublishAppNetworkConfig(getconfigCtx *getconfigContext, key string) {
log.Tracef("unpublishAppNetworkConfig %s", key)
pub := getconfigCtx.pubAppNetworkConfig
c, _ := pub.Get(key)
if c == nil {
log.Errorf("unpublishAppNetworkConfig(%s) not found", key)
return
}
pub.Unpublish(key)
}
func addrStringToIP(addrString string) (net.IP, error) {
clientTCP, err := net.ResolveTCPAddr("tcp", addrString)
if err != nil {
return net.IP{}, err
}
return clientTCP.IP, nil
}
// IsMyAddress checks the IP address against the local IPs. Returns True if
// there is a match.
func IsMyAddress(clientIP net.IP) bool {
addrs, err := net.InterfaceAddrs()
if err != nil {
return false
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok &&
!ipnet.IP.IsLoopback() {
if bytes.Compare(ipnet.IP, clientIP) == 0 {
return true
}
}
}
return false
}