summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authordautor <karlo98.m@gmail.com>2024-11-16 20:12:45 +0100
committerdautor <karlo98.m@gmail.com>2024-11-16 20:12:45 +0100
commit9638b621fa567555e51c9bc61351a708221fd2ee (patch)
treed16248bfc8d0d7704da8c99585a580dda16f7518 /src/util.c
parent47778ccd67cbb3fb70dda706911d3166038ca010 (diff)
Add ng_pipe link
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index f7d0aef..13ba790 100644
--- a/src/util.c
+++ b/src/util.c
@@ -37,7 +37,7 @@ Create_eiface(u32 *ID, fd Control)
strcpy(D.peerhook, "ether");
if(NgSendMsg(Control, ".:", NGM_GENERIC_COOKIE, NGM_MKPEER, &D, sizeof(D)) == -1)
{
- fprintf(stderr, "ngctl mkpeer .: eiface _ ether: %s\n", strerror(errno));
+ fprintf(stderr, "ngctl mkpeer .: eiface _ ether: %s\n", strerror(errno));
goto error;
}
}
@@ -83,7 +83,7 @@ Create_bridge(u32 *ID, fd Control)
strcpy(D.peerhook, "link0");
if(NgSendMsg(Control, ".:", NGM_GENERIC_COOKIE, NGM_MKPEER, &D, sizeof(D)) == -1)
{
- fprintf(stderr, "ngctl mkpeer .: eiface _ ether: %s\n", strerror(errno));
+ fprintf(stderr, "ngctl mkpeer .: bridge _ link0: %s\n", strerror(errno));
goto error;
}
}
@@ -125,6 +125,69 @@ error:
return -1;
}
+int
+Create_pipe(u32 *ID, fd Control, char const *NodeA, char const *NodeB, char const *HookA, char const *HookB)
+{
+ *ID = 0;
+ {
+ struct ngm_mkpeer D;
+ strcpy(D.type, "pipe");
+ strncpy(D.ourhook, HookA, sizeof(D.ourhook));
+ strcpy(D.peerhook, "lower");
+ if(NgSendMsg(Control, NodeA, NGM_GENERIC_COOKIE, NGM_MKPEER, &D, sizeof(D)) == -1)
+ {
+ fprintf(stderr, "ngctl mkpeer %s pipe %s lower: %s\n", NodeA, HookA, strerror(errno));
+ goto error;
+ }
+ }
+ char Path[NG_PATHSIZ];
+ {
+ snprintf(Path, sizeof(Path), "%s%s", NodeA, HookA);
+ if(NgSendMsg(Control, Path, NGM_GENERIC_COOKIE, NGM_NODEINFO, NULL, 0) == -1)
+ {
+ fprintf(stderr, "ngctl info %s : %s\n", Path, strerror(errno));
+ goto error;
+ }
+ struct ng_mesg *Response;
+ if(NgAllocRecvMsg(Control, &Response, NULL) == -1)
+ {
+ fprintf(stderr, "NgAllocRecvMsg: %s\n", strerror(errno));
+ return -1;
+ }
+ struct nodeinfo *Info = (void *)Response->data;
+ *ID = Info->id;
+ free(Response);
+ }
+ if(ng_connect(Control, NodeB, Path, HookB, "upper") == -1) goto error;
+ return 0;
+error:
+ if(*ID != 0) DestroyNetgraphNode(*ID, Control);
+ return -1;
+}
+
+int
+ng_connect(fd Control, char const *NodeA, char const *NodeB, char const *HookA, char const *HookB)
+{
+ struct ngm_connect D;
+ char Path0[NG_PATHSIZ];
+ strncpy(Path0, NodeA, sizeof(Path0));
+ strncpy(D.path, NodeB, sizeof(D.path));
+ strncpy(D.ourhook, HookA, sizeof(D.ourhook));
+ strncpy(D.peerhook, HookB, sizeof(D.peerhook));
+ if(NgSendMsg(Control, Path0, NGM_GENERIC_COOKIE, NGM_CONNECT, &D, sizeof(D)) == -1)
+ {
+ fprintf(stderr,
+ "ngctl connect %s %s %s %s: %s\n",
+ Path0,
+ D.path,
+ D.ourhook,
+ D.peerhook,
+ strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
char *
getifname(u32 ID, fd Control)
{