Sfoglia il codice sorgente

[syslog] Add support for IPv6 syslog server

Note that IANA has not yet assigned a DHCPv6 option code for the
syslog server.  When a code is assigned, the definition of
DHCPV6_LOG_SERVERS should be updated.  Until then, an IPv6 address of
a syslog server can be configured manually using e.g.

  set syslog6 3ffe:302:11:2::8309

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 anni fa
parent
commit
44a0dc7848
3 ha cambiato i file con 42 aggiunte e 17 eliminazioni
  1. 7
    0
      src/include/ipxe/dhcpv6.h
  2. 0
    1
      src/net/tcp/syslogs.c
  3. 35
    16
      src/net/udp/syslog.c

+ 7
- 0
src/include/ipxe/dhcpv6.h Vedi File

@@ -152,6 +152,13 @@ struct dhcpv6_user_class_option {
152 152
 /** DHCPv6 domain search list option */
153 153
 #define DHCPV6_DOMAIN_LIST 24
154 154
 
155
+/** DHCPv6 syslog server option
156
+ *
157
+ * This option code has not yet been assigned by IANA.  Please update
158
+ * this definition once an option code has been assigned.
159
+ */
160
+#define DHCPV6_LOG_SERVERS 0xffffffffUL
161
+
155 162
 /**
156 163
  * Any DHCPv6 option
157 164
  *

+ 0
- 1
src/net/tcp/syslogs.c Vedi File

@@ -49,7 +49,6 @@ struct console_driver syslogs_console __console_driver;
49 49
 
50 50
 /** The encrypted syslog server */
51 51
 static struct sockaddr_tcpip logserver = {
52
-	.st_family = AF_INET,
53 52
 	.st_port = htons ( SYSLOG_PORT ),
54 53
 };
55 54
 

+ 35
- 16
src/net/udp/syslog.c Vedi File

@@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
32 32
 #include <ipxe/open.h>
33 33
 #include <ipxe/tcpip.h>
34 34
 #include <ipxe/dhcp.h>
35
+#include <ipxe/dhcpv6.h>
35 36
 #include <ipxe/settings.h>
36 37
 #include <ipxe/console.h>
37 38
 #include <ipxe/lineconsole.h>
@@ -45,9 +46,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
45 46
 #endif
46 47
 
47 48
 /** The syslog server */
48
-static struct sockaddr_tcpip logserver = {
49
-	.st_family = AF_INET,
50
-	.st_port = htons ( SYSLOG_PORT ),
49
+static union {
50
+	struct sockaddr sa;
51
+	struct sockaddr_tcpip st;
52
+	struct sockaddr_in sin;
53
+	struct sockaddr_in6 sin6;
54
+} logserver = {
55
+	.st = {
56
+		.st_port = htons ( SYSLOG_PORT ),
57
+	},
51 58
 };
52 59
 
53 60
 /** Syslog UDP interface operations */
@@ -187,7 +194,7 @@ struct console_driver syslog_console __console_driver = {
187 194
  ******************************************************************************
188 195
  */
189 196
 
190
-/** Syslog server setting */
197
+/** IPv4 syslog server setting */
191 198
 const struct setting syslog_setting __setting ( SETTING_MISC ) = {
192 199
 	.name = "syslog",
193 200
 	.description = "Syslog server",
@@ -195,16 +202,22 @@ const struct setting syslog_setting __setting ( SETTING_MISC ) = {
195 202
 	.type = &setting_type_ipv4,
196 203
 };
197 204
 
205
+/** IPv6 syslog server setting */
206
+const struct setting syslog6_setting __setting ( SETTING_MISC ) = {
207
+	.name = "syslog6",
208
+	.description = "Syslog server",
209
+	.tag = DHCPV6_LOG_SERVERS,
210
+	.type = &setting_type_ipv6,
211
+	.scope = &ipv6_scope,
212
+};
213
+
198 214
 /**
199 215
  * Apply syslog settings
200 216
  *
201 217
  * @ret rc		Return status code
202 218
  */
203 219
 static int apply_syslog_settings ( void ) {
204
-	struct sockaddr_in *sin_logserver =
205
-		( struct sockaddr_in * ) &logserver;
206
-	struct in_addr old_addr;
207
-	int len;
220
+	struct sockaddr old_logserver;
208 221
 	int rc;
209 222
 
210 223
 	/* Fetch hostname and domain name */
@@ -215,14 +228,23 @@ static int apply_syslog_settings ( void ) {
215 228
 
216 229
 	/* Fetch log server */
217 230
 	syslog_console.disabled = CONSOLE_DISABLED;
218
-	old_addr.s_addr = sin_logserver->sin_addr.s_addr;
219
-	if ( ( len = fetch_ipv4_setting ( NULL, &syslog_setting,
220
-					  &sin_logserver->sin_addr ) ) >= 0 ) {
231
+	memcpy ( &old_logserver, &logserver, sizeof ( old_logserver ) );
232
+	logserver.sa.sa_family = 0;
233
+	if ( fetch_ipv6_setting ( NULL, &syslog6_setting,
234
+				  &logserver.sin6.sin6_addr ) >= 0 ) {
235
+		logserver.sin6.sin6_family = AF_INET6;
236
+	} else if ( fetch_ipv4_setting ( NULL, &syslog_setting,
237
+					 &logserver.sin.sin_addr ) >= 0 ) {
238
+		logserver.sin.sin_family = AF_INET;
239
+	}
240
+	if ( logserver.sa.sa_family ) {
221 241
 		syslog_console.disabled = 0;
242
+		DBG ( "SYSLOG using log server %s\n",
243
+		      sock_ntoa ( &logserver.sa ) );
222 244
 	}
223 245
 
224 246
 	/* Do nothing unless log server has changed */
225
-	if ( sin_logserver->sin_addr.s_addr == old_addr.s_addr )
247
+	if ( memcmp ( &logserver, &old_logserver, sizeof ( logserver ) ) == 0 )
226 248
 		return 0;
227 249
 
228 250
 	/* Reset syslog connection */
@@ -236,14 +258,11 @@ static int apply_syslog_settings ( void ) {
236 258
 
237 259
 	/* Connect to log server */
238 260
 	if ( ( rc = xfer_open_socket ( &syslogger, SOCK_DGRAM,
239
-				       ( ( struct sockaddr * ) &logserver ),
240
-				       NULL ) ) != 0 ) {
261
+				       &logserver.sa, NULL ) ) != 0 ) {
241 262
 		DBG ( "SYSLOG cannot connect to log server: %s\n",
242 263
 		      strerror ( rc ) );
243 264
 		return rc;
244 265
 	}
245
-	DBG ( "SYSLOG using log server %s\n",
246
-	      inet_ntoa ( sin_logserver->sin_addr ) );
247 266
 
248 267
 	return 0;
249 268
 }

Loading…
Annulla
Salva