|
@@ -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
|
}
|