summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2019-01-16 11:26:56 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2019-01-16 12:10:15 +0100
commitdee6cbec255c3a8af7f79fd7e401d231a5cbbb93 (patch)
tree1e4487cdacaa69ac222c837c7fee26c8fdefec16 /src/tools
parent91e69340799866966eb9b7acc63f404424f23dee (diff)
downloadouroboros-dee6cbec255c3a8af7f79fd7e401d231a5cbbb93.tar.gz
ouroboros-dee6cbec255c3a8af7f79fd7e401d231a5cbbb93.zip
tools: Allow enrollment with destination IPCP
The irm enroll tool had a semantic to enroll with a layer name, but this is not checked. Now the enroll command will retrieve the correct layer name that the IPCP got from the actual enrollment procedure. The irm enroll now has two string parameters, a dst and a layer, which cannot be both NULL. If only dst is specified, the IPCP will enroll with that name; autobind will bind with the layer name. If only layer is specified, the IPCP will enroll with the layer name, and perform a check that the layer name retrieved from enrollment is indeed the layer name before possibly autobinding. If both dst and layer are specified, the IPCP will enroll with dst and perform a check that the enrollment was in the expected layer. Basically only specifying the layer name is a shorthand for dst == layer. Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/irm/irm_ipcp_enroll.c63
1 files changed, 52 insertions, 11 deletions
diff --git a/src/tools/irm/irm_ipcp_enroll.c b/src/tools/irm/irm_ipcp_enroll.c
index 5b6caf55..082f2c52 100644
--- a/src/tools/irm/irm_ipcp_enroll.c
+++ b/src/tools/irm/irm_ipcp_enroll.c
@@ -46,24 +46,46 @@
#include <string.h>
-#define NORMAL "normal"
+#define NORMAL "unicast"
#define BROADCAST "broadcast"
static void usage(void)
{
printf("Usage: irm ipcp enroll\n"
" name <ipcp name>\n"
- " layer <layer to enroll in>\n"
- " [type [TYPE], default = normal]\n"
+ " [layer <layer to enroll with>]\n"
+ " [dst <destination to enroll with>]\n"
+ " [type [TYPE], default = " NORMAL "]\n"
" [autobind]\n"
"where TYPE = {" NORMAL " " BROADCAST "}\n");
}
+static int get_layer_name(const char * ipcp,
+ char * layer_name)
+{
+ struct ipcp_info * ipcps;
+ size_t len;
+ size_t i;
+
+ len = irm_list_ipcps(&ipcps);
+ for (i = 0; i < len; i++)
+ if (strcmp(ipcps[i].name, ipcp) == 0) {
+ strcpy(layer_name, ipcps[i].layer);
+ free(ipcps);
+ return 0;
+ }
+
+ free(ipcps);
+
+ return -1;
+}
+
int do_enroll_ipcp(int argc,
char ** argv)
{
char * ipcp = NULL;
char * layer = NULL;
+ char * dst = NULL;
struct ipcp_info * ipcps;
pid_t pid = -1;
ssize_t len = 0;
@@ -81,6 +103,8 @@ int do_enroll_ipcp(int argc,
ipcp_type = *(argv + 1);
} else if (matches(*argv, "layer") == 0) {
layer = *(argv + 1);
+ } else if (matches(*argv, "dst") == 0) {
+ dst = *(argv + 1);
} else if (matches(*argv, "autobind") == 0) {
autobind = true;
cargs = 1;
@@ -94,11 +118,14 @@ int do_enroll_ipcp(int argc,
argv += cargs;
}
- if (layer == NULL || ipcp == NULL) {
+ if ((layer == NULL && dst == NULL) || ipcp == NULL) {
usage();
return -1;
}
+ if (dst == NULL)
+ dst = layer;
+
if (strcmp(ipcp_type, NORMAL) == 0)
type = IPCP_NORMAL;
else if (strcmp(ipcp_type, BROADCAST) == 0)
@@ -121,22 +148,36 @@ int do_enroll_ipcp(int argc,
for (i = 0; i < len; i++) {
if (ipcps[i].type != type)
continue;
+
if (wildcard_match(ipcps[i].name, ipcp) == 0) {
+ char enr_layer[LAYER_NAME_SIZE];
+
pid = ipcps[i].pid;
- if (autobind && irm_bind_process(pid, ipcp)) {
- printf("Failed to bind %d to %s.\n", pid, ipcp);
+
+ if (irm_enroll_ipcp(pid, dst)) {
+ printf("Failed to enroll IPCP.\n");
goto fail;
}
- if (irm_enroll_ipcp(pid, layer)) {
- if (autobind)
- irm_unbind_process(pid, ipcp);
+ if (get_layer_name(ipcps[i].name, enr_layer)) {
+ printf("Could not get layer name.\n");
+ goto fail;
+ }
+
+ if (layer != NULL && strcmp(enr_layer, layer)) {
+ printf("Enrollment destination does not "
+ "match requested layer.\n");
+ goto fail;
+ }
+
+ if (autobind && irm_bind_process(pid, ipcp)) {
+ printf("Failed to bind %d to %s.\n", pid, ipcp);
goto fail;
}
- if (autobind && irm_bind_process(pid, layer)) {
+ if (autobind && irm_bind_process(pid, enr_layer)) {
printf("Failed to bind %d to %s.\n",
- pid, layer);
+ pid, enr_layer);
goto fail;
}
}