summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2017-09-25 18:20:52 +0300
committerDmitry Kozlov <xeb@mail.ru>2017-09-26 11:58:41 +0300
commit08e048a76d1d566bf280e3c09d4d839ff40f7af7 (patch)
treee5e9e528fcd068f58ed13be9c97a694903992a3a
parentb766b41e8ae93e4b67dcbfb128aa27bdb86ece6a (diff)
downloadaccel-ppp-08e048a76d1d566bf280e3c09d4d839ff40f7af7.tar.gz
accel-ppp-08e048a76d1d566bf280e3c09d4d839ff40f7af7.zip
cli: introduced ip6 and ip6-dp fields in "show sessions" command
-rw-r--r--accel-pppd/cli/show_sessions.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c
index fd2f2b43..eabf95bc 100644
--- a/accel-pppd/cli/show_sessions.c
+++ b/accel-pppd/cli/show_sessions.c
@@ -392,9 +392,64 @@ static void print_username(struct ap_session *ses, char *buf)
*buf = 0;
}
+static void print_ip6_dp(struct ap_session *ses, char *buf)
+{
+ struct ipv6db_addr_t *a;
+ char *ptr;
+
+ if (!ses->ipv6_dp) {
+ *buf = 0;
+ return;
+ }
+
+ a = list_entry(ses->ipv6_dp->prefix_list.next, typeof(*a), entry);
+ inet_ntop(AF_INET6, &a->addr, buf, 64);
+ ptr = strchr(buf, 0);
+ sprintf(ptr, "/%i", a->prefix_len);
+}
+
+static void build_ip6_addr(struct ipv6db_addr_t *a, uint64_t intf_id, struct in6_addr *addr)
+{
+ memcpy(addr, &a->addr, sizeof(*addr));
+
+ if (a->prefix_len <= 64)
+ *(uint64_t *)(addr->s6_addr + 8) = intf_id;
+ else
+ *(uint64_t *)(addr->s6_addr + 8) |= intf_id & ((1 << (128 - a->prefix_len)) - 1);
+}
+
+static void print_ip6(struct ap_session *ses, char *buf)
+{
+ struct ipv6db_addr_t *a;
+ struct in6_addr addr;
+ char *ptr;
+
+ if (!ses->ipv6) {
+ *buf = 0;
+ return;
+ }
+
+ a = list_entry(ses->ipv6->addr_list.next, typeof(*a), entry);
+ if (a->prefix_len == 0) {
+ *buf = 0;
+ return;
+ }
+
+ build_ip6_addr(a, ses->ipv6->peer_intf_id, &addr);
+
+ inet_ntop(AF_INET6, &addr, buf, 64);
+ ptr = strchr(buf, 0);
+ sprintf(ptr, "/%i", a->prefix_len);
+}
+
static void print_ip(struct ap_session *ses, char *buf)
{
- u_inet_ntoa(ses->ipv4 ? ses->ipv4->peer_addr : 0, buf);
+ if (!ses->ipv4) {
+ print_ip6(ses,buf);
+ return;
+ }
+
+ u_inet_ntoa(ses->ipv4->peer_addr, buf);
}
static void print_type(struct ap_session *ses, char *buf)
@@ -579,6 +634,8 @@ static void init(void)
cli_show_ses_register("ifname", "interface name", print_ifname);
cli_show_ses_register("username", "user name", print_username);
cli_show_ses_register("ip", "IP address", print_ip);
+ cli_show_ses_register("ip6", "IPv6 address", print_ip6);
+ cli_show_ses_register("ip6-dp", "IPv6 delegated prefix", print_ip6_dp);
cli_show_ses_register("type", "VPN type", print_type);
cli_show_ses_register("state", "state of session", print_state);
cli_show_ses_register("uptime", "uptime", print_uptime);