Skip to content

Commit b3d936f

Browse files
Cong Wangdavem330
authored andcommitted
netpoll: add IPv6 support
Currently, netpoll only supports IPv4. This patch adds IPv6 support to netpoll so that we can run netconsole over IPv6 network. Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Cong Wang <amwang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent acb3e04 commit b3d936f

2 files changed

Lines changed: 274 additions & 16 deletions

File tree

‎drivers/net/netconsole.c‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,17 @@ static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
269269

270270
static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
271271
{
272-
if (!nt->np.ipv6)
272+
if (nt->np.ipv6)
273+
return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.local_ip.in6);
274+
else
273275
return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip);
274276
}
275277

276278
static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
277279
{
278-
if (!nt->np.ipv6)
280+
if (nt->np.ipv6)
281+
return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.remote_ip.in6);
282+
else
279283
return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip);
280284
}
281285

@@ -412,8 +416,22 @@ static ssize_t store_local_ip(struct netconsole_target *nt,
412416
return -EINVAL;
413417
}
414418

415-
if (!strnchr(buf, count, ':'))
416-
nt->np.local_ip.ip = in_aton(buf);
419+
if (strnchr(buf, count, ':')) {
420+
const char *end;
421+
if (in6_pton(buf, count, nt->np.local_ip.in6.s6_addr, -1, &end) > 0) {
422+
if (*end && *end != '\n') {
423+
printk(KERN_ERR "netconsole: invalid IPv6 address at: <%c>\n", *end);
424+
return -EINVAL;
425+
}
426+
nt->np.ipv6 = true;
427+
} else
428+
return -EINVAL;
429+
} else {
430+
if (!nt->np.ipv6) {
431+
nt->np.local_ip.ip = in_aton(buf);
432+
} else
433+
return -EINVAL;
434+
}
417435

418436
return strnlen(buf, count);
419437
}
@@ -429,8 +447,22 @@ static ssize_t store_remote_ip(struct netconsole_target *nt,
429447
return -EINVAL;
430448
}
431449

432-
if (!strnchr(buf, count, ':'))
433-
nt->np.remote_ip.ip = in_aton(buf);
450+
if (strnchr(buf, count, ':')) {
451+
const char *end;
452+
if (in6_pton(buf, count, nt->np.remote_ip.in6.s6_addr, -1, &end) > 0) {
453+
if (*end && *end != '\n') {
454+
printk(KERN_ERR "netconsole: invalid IPv6 address at: <%c>\n", *end);
455+
return -EINVAL;
456+
}
457+
nt->np.ipv6 = true;
458+
} else
459+
return -EINVAL;
460+
} else {
461+
if (!nt->np.ipv6) {
462+
nt->np.remote_ip.ip = in_aton(buf);
463+
} else
464+
return -EINVAL;
465+
}
434466

435467
return strnlen(buf, count);
436468
}

0 commit comments

Comments
 (0)