aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrtr-origin/rtr-origin.py71
1 files changed, 48 insertions, 23 deletions
diff --git a/rtr-origin/rtr-origin.py b/rtr-origin/rtr-origin.py
index 4af4199c..41d1cf0b 100755
--- a/rtr-origin/rtr-origin.py
+++ b/rtr-origin/rtr-origin.py
@@ -1260,6 +1260,53 @@ class kickme_channel(asyncore.dispatcher):
asyncore.close_all()
+def hostport_tag():
+ """
+ Construct hostname/address + port when we're running under a
+ protocol we understand well enough to do that. This is all
+ kludgery. Just grit your teeth, or perhaps just close your eyes.
+ """
+
+ proto = None
+
+ if proto is None:
+ try:
+ host, port = socket.fromfd(0, socket.AF_INET, socket.SOCK_STREAM).getpeername()
+ proto = "tcp"
+ except:
+ pass
+
+ if proto is None:
+ try:
+ host, port = socket.fromfd(0, socket.AF_INET6, socket.SOCK_STREAM).getpeername()[0:2]
+ proto = "tcp"
+ except:
+ pass
+
+ if proto is None:
+ try:
+ host, port = os.environ["SSH_CONNECTION"].split()[0:2]
+ proto = "ssh"
+ except:
+ pass
+
+ if proto is None:
+ try:
+ host, port = os.environ["REMOTE_HOST"], os.getenv("REMOTE_PORT")
+ proto = "ssl"
+ except:
+ pass
+
+ if proto is None:
+ return ""
+ elif not port:
+ return "/%s/%s" % (proto, host)
+ elif ":" in host:
+ return "/%s/%s.%s" % (proto, host, port)
+ else:
+ return "/%s/%s:%s" % (proto, host, port)
+
+
def kick_all(serial):
"""
Kick any existing server processes to wake them up.
@@ -1692,29 +1739,7 @@ if mode is None:
log_tag = "rtr-origin/" + mode
if mode in ("server", "bgpdump_server"):
- #
- # Try to figure out peer address when we're in server mode.
- def hostport_to_string(proto, hostport):
- assert len(hostport) == 2
- if hostport[1] is None or hostport[1] == "":
- return "/%s/%s" % (proto, hostport[0])
- elif ":" in hostport[0]:
- return "/%s/%s.%s" % (proto, hostport[0], hostport[1])
- else:
- return "/%s/%s:%s" % (proto, hostport[0], hostport[1])
- #
- # First try raw TCP, TCP-MD5, TCP-AO
- try:
- log_tag += hostport_to_string("tcp", socket.fromfd(0, socket.AF_INET, socket.SOCK_STREAM).getpeername())
- except (socket.error, IndexError):
- #
- # Next try ssh (sshd sets environment)
- if "SSH_CONNECTION" in os.environ:
- log_tag += hostport_to_string("ssh", os.environ["SSH_CONNECTION"].split()[0:2])
- #
- # Next try ssl (stunnel sets environment)
- elif "REMOTE_HOST" in os.environ:
- log_tag += hostport_to_string("ssl", (os.environ["REMOTE_HOST"], os.getenv("REMOTE_PORT")))
+ log_tag += hostport_tag()
if mode in ("cronjob", "server" , "bgpdump_server"):
syslog.openlog(log_tag, syslog.LOG_PID, syslog.LOG_DAEMON)
gh.' href='/sra/rpki.net/commit/scripts/ripe-to-csv.py?h=zone-cleanup&id=e23dab52b6b7eef868bfbee2842aa6fc924050cc'>e23dab52
f5c70298


e23dab52
f5c70298


59e460f6
f5c70298
f5c70298













f5c70298


5c03bbdc

f5c70298












b271d1d7

f5c70298

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138