diff options
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 67 |
1 files changed, 65 insertions, 2 deletions
@@ -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) { |
