aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schultz <aschultz@tpip.net>2019-03-18 09:09:11 +0000
committerPau Espin Pedrol <pespin@sysmocom.de>2020-03-02 09:42:57 +0100
commit26df01275dd31153ba7d875c3113c0aaf10b371c (patch)
treee41f213295c3aa29ce49c9fda0901047f6899754
parentad6eaa28811f96ebc39b5723cc37abb144ae82e6 (diff)
IPv4v6 PDP context type in sgsnemupespin/tp
-rw-r--r--lib/tun.c32
-rw-r--r--lib/tun.h4
-rw-r--r--sgsnemu/cmdline.c2
-rw-r--r--sgsnemu/cmdline.ggo2
-rw-r--r--sgsnemu/sgsnemu.c14
5 files changed, 50 insertions, 4 deletions
diff --git a/lib/tun.c b/lib/tun.c
index 1aeed55..b6a9652 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -364,3 +364,35 @@ int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list, s
{
return netdev_ip_local_get(tun->devname, prefix_list, prefix_size, flags);
}
+
+#if defined(__linux__)
+
+int tun_settoken(struct tun_t *tun, struct in46_addr *addr)
+{
+ struct in46_addr token;
+ char buf[2048];
+ int rc;
+
+ rc = system("/sbin/ip token list");
+
+ token = *addr;
+ memset(token.v6.s6_addr, 0, 8);
+
+ printf("TUN Interface Addr: %s\n", in46a_ntoa(addr));
+ printf("TUN Interface token: %s\n", in46a_ntoa(&token));
+
+ /* system("ip token set ::1/64 dev tun0"); */
+ snprintf(buf, sizeof(buf), "/sbin/ip token set %s/64 dev %s",
+ in46a_ntoa(&token), tun->devname);
+ buf[sizeof(buf) - 1] = 0;
+ printf("Exec TUN CMD: %s\n", buf);
+ rc = system(buf);
+ if (rc == -1) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "Error executing command %s", buf);
+ return -1;
+ }
+ return 0;
+}
+
+#endif
diff --git a/lib/tun.h b/lib/tun.h
index 07ca04a..397c7f2 100644
--- a/lib/tun.h
+++ b/lib/tun.h
@@ -59,4 +59,8 @@ extern int tun_runscript(struct tun_t *tun, char *script);
int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list,
size_t prefix_size, int flags);
+#if defined(__linux__)
+extern int tun_settoken(struct tun_t *tun, struct in46_addr *addr);
+#endif
+
#endif /* !_TUN_H */
diff --git a/sgsnemu/cmdline.c b/sgsnemu/cmdline.c
index 13d0295..21ac665 100644
--- a/sgsnemu/cmdline.c
+++ b/sgsnemu/cmdline.c
@@ -80,7 +80,7 @@ const char *gengetopt_args_info_help[] = {
" --pingcount=INT Number of ping req to send (default=`0')",
" --pingquiet Do not print ping packet info (default=off)",
" --no-tx-gpdu-seq Don't transmit G-PDU sequence nums\n (default=off)",
- " -t, --pdp-type=(v4|v6) PDP Type (default=`v4')",
+ " -t, --pdp-type=(v4|v6|v4v6) PDP Type (default=`v4')",
0
};
diff --git a/sgsnemu/cmdline.ggo b/sgsnemu/cmdline.ggo
index 0d074aa..3394e76 100644
--- a/sgsnemu/cmdline.ggo
+++ b/sgsnemu/cmdline.ggo
@@ -68,4 +68,4 @@ modeoption "pingcount" - "Number of ping req to send" int default="0" d
modeoption "pingquiet" - "Do not print ping packet info" flag dependon="pinghost" off mode="pinghost"
option "no-tx-gpdu-seq" - "Don't transmit G-PDU sequence nums" flag off
-option "pdp-type" t "PDP Type" string default="v4" no typestr="(v4|v6)"
+option "pdp-type" t "PDP Type" string default="v4" no typestr="(v4|v6|v4v6)"
diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c
index fce5059..5af6b62 100644
--- a/sgsnemu/sgsnemu.c
+++ b/sgsnemu/sgsnemu.c
@@ -949,13 +949,16 @@ static int process_options(int argc, char **argv)
options.pdp_type = PDP_EUA_TYPE_v6;
else if (!strcmp(args_info.pdp_type_arg, "v4"))
options.pdp_type = PDP_EUA_TYPE_v4;
+ else if (!strcmp(args_info.pdp_type_arg, "v4v6"))
+ options.pdp_type = PDP_EUA_TYPE_v4v6;
else {
SYS_ERR(DSGSN, LOGL_ERROR, 0, "Unsupported/unknown PDP Type '%s'\n",
args_info.pdp_type_arg);
return -1;
}
- if (options.pingcount && options.pdp_type != PDP_EUA_TYPE_v4) {
+ if (options.pingcount && (options.pdp_type != PDP_EUA_TYPE_v4 &&
+ options.pdp_type != PDP_EUA_TYPE_v4v6)) {
SYS_ERR(DSGSN, LOGL_ERROR, 0, "built-in ping only works with IPv4, use tun-device");
return -1;
}
@@ -1483,6 +1486,12 @@ static int create_pdp_conf(struct pdp_t *pdp, void *cbp, int cause)
prefixlen = 64;
/* printf("Setting up interface and routing\n"); */
tun_addaddr(tun, &addr, &addr, prefixlen);
+
+#if defined(__linux__)
+ if (addr.len == 16)
+ tun_settoken(tun, &addr);
+#endif
+
if (options.defaultroute) {
struct in_addr rm;
rm.s_addr = 0;
@@ -1494,7 +1503,8 @@ static int create_pdp_conf(struct pdp_t *pdp, void *cbp, int cause)
/* now that ip-up has been executed, check if we are configured to
* accept router advertisements */
- if (options.createif && options.pdp_type == PDP_EUA_TYPE_v6) {
+ if (options.createif && (options.pdp_type == PDP_EUA_TYPE_v6 ||
+ options.pdp_type == PDP_EUA_TYPE_v4v6)) {
char *accept_ra, *forwarding;
accept_ra = proc_ipv6_conf_read(tun->devname, "accept_ra");