aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-10-13 18:54:59 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-10-13 18:54:59 +0200
commit62eb741c74df712a3fa47d7de4cb8112f42e36e1 (patch)
tree0db8ed208842a45733b428ea5a5ef6066608436f
parentprotocol doc (diff)
downloadglouglou-62eb741c74df712a3fa47d7de4cb8112f42e36e1.tar.xz
glouglou-62eb741c74df712a3fa47d7de4cb8112f42e36e1.zip
libglouglou modules
-rw-r--r--v3/libglouglou/libglouglou_mod_0_internal/libglouglou_mod_0_internal.c177
-rw-r--r--v3/libglouglou/libglouglou_mod_0_internal/libglouglou_mod_0_internal.h64
-rw-r--r--v3/libglouglou/libglouglou_mod_1_net/Makefile16
3 files changed, 257 insertions, 0 deletions
diff --git a/v3/libglouglou/libglouglou_mod_0_internal/libglouglou_mod_0_internal.c b/v3/libglouglou/libglouglou_mod_0_internal/libglouglou_mod_0_internal.c
new file mode 100644
index 0000000..23e6d36
--- /dev/null
+++ b/v3/libglouglou/libglouglou_mod_0_internal/libglouglou_mod_0_internal.c
@@ -0,0 +1,177 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "libglouglou_mod_0_internal.h"
+
+#define NEWPKT(newpkt_pkt, newpkt_body, newpkt_type) \
+ struct ggpkt *newpkt_pkt; \
+ struct ggpkt_mod_0_internal *newpkt_body; \
+ \
+ newpkt_body = xcalloc(1, sizeof(struct ggpkt_mod_0_internal)); \
+ newpkt_body->type = newpkt_type; \
+ newpkt_pkt = ggpkt_new(GGPKT_MOD_0_INTERNAL_ID, \
+ GGPKT_MOD_0_INTERNAL_VERSION, \
+ newpkt_body, _get_len);
+
+struct ggpkt *
+ggpkt_mod_0_internal_hello(void)
+{
+ NEWPKT(pkt, body, GGPKT_MOD_0_INTERNAL_HELLO)
+ body->data.hello.random_probe = htonl(rand());
+ return pkt;
+}
+
+struct ggpkt *
+ggpkt_mod_0_internal_hello_res(void)
+{
+ NEWPKT(pkt, body, GGPKT_MOD_0_INTERNAL_HELLO_RES)
+ body->data.hello.random_ggd = htonl(rand());
+ return pkt;
+}
+
+struct ggpkt *
+ggpkt_mod_0_internal_hello_auth(int probe_id, char *pass,
+ int random_probe, int random_ggd)
+{
+ int len;
+
+ len = strlen(pass);
+ if (len > GGPKT_ARG_MAX)
+ return -1;
+
+ NEWPKT(pkt, body, GGPKT_MOD_0_INTERNAL_AUTH)
+ body->data.auth.probe_id = htons(probe_id);
+ body->data.auth.probe_password_len = len;
+ memcpy(body->data.auth.probe_password, pass, len+1);
+ body->data.hello.random_probe = htonl(random_probe);
+ body->data.hello.random_ggd = htonl(random_ggd);
+ return body;
+}
+
+struct ggpkt *
+ggpkt_mod_0_internal_auth_res(int status)
+{
+ NEWPKT(pkt, body, GGPKT_MOD_0_INTERNAL_AUTH_RES)
+ body->data.auth_res.status = status;
+ return pkt;
+}
+
+struct ggpkt *
+ggpkt_mod_0_internal_notice(char *notice_msg)
+{
+ int len;
+
+ len = strlen(notice_msg);
+ if (len > GGPKT_ARG_MAX)
+ return -1;
+
+ NEWPKT(pkt, body, GGPKT_MOD_0_INTERNAL_NOTICE)
+ body->data.notice.len = len;
+ memcpy(body->data.notice.msg, notice_msg, len+1);
+ return pkt;
+}
+
+struct ggpkt *
+ggpkt_mod_0_internal_ping(void)
+{
+ NEWPKT(pkt, body, GGPKT_MOD_0_INTERNAL_PING)
+ body->data.ping.random = rand();
+ return pkt;
+}
+
+struct ggpkt *
+ggpkt_mod_0_internal_ping_res(int random_res)
+{
+ NEWPKT(pkt, body, GGPKT_MOD_0_INTERNAL_PING_RES)
+ body->data.ping.random_res = random_res;
+ return pkt;
+}
+
+/* return pointer to static decode packet from received buffer */
+struct ggpkt_mod_0_internal *
+ggpkt_mod_0_internal_decode(char *buf)
+{
+ struct ggpkt_mod_0_internal *bufbody;
+ static struct ggpkt_mod_0_internal body;
+
+ bufbody = (struct ggpkt_mod_0_internal *)body;
+ body.type = bufbody->type;
+ switch (body.type) {
+ case GGPKT_MOD_0_INTERNAL_HELLO:
+ body.data.hello.random_probe = ntohl(bufbody->data.hello.random_probe);
+ break;
+ case GGPKT_MOD_0_INTERNAL_HELLO_RES:
+ body.data.hello.random_ggd = ntohl(bufbody->data.hello.random_ggd);
+ break;
+ case GGPKT_MOD_0_INTERNAL_AUTH:
+ body.data.auth.probe_id = ntohs(bufbody->data.auth.probe_id);
+ body.data.auth.probe_password_len = bufbody->data.auth.len;
+ memcpy(body.data.auth.probe_password, bufbody->data.auth.probe_password,
+ body.data.auth.probe_password_len);
+ body.data.hello.random_probe = ntohl(bufbody->data.auth.random_probe);
+ body.data.hello.random_ggd = ntohl(bufbody->data.auth.random_ggd);
+ break;
+ case GGPKT_MOD_0_INTERNAL_AUTH_RES:
+ body.data.auth_res.random_ggd = ntohl(bufbody->data.auth_res.random_ggd);
+ break;
+ case GGPKT_MOD_0_INTERNAL_NOTICE:
+ body.data.notice.len = ntohs(bufbody->data.notice.len);
+ memcpy(body.data.notice.msg, bufbody->data.notice.msg,
+ body.data.notice.len);
+ break;
+ case GGPKT_MOD_0_INTERNAL_PING:
+ body.data.ping.random = ntohl(bufbody->data.ping.random);
+ break;
+ case GGPKT_MOD_0_INTERNAL_PING_RES:
+ body.data.ping_res.random_res = ntohl(bufbody->data.ping_res.random_res);
+ break;
+ default:
+ goto err;
+ /* UNREACHED */
+ }
+
+ return &body;
+
+err:
+ return NULL;
+}
+
+int
+_get_len(struct ggpkt *pkt)
+{
+ struct ggpkt_mod_0_internal *body;
+ int size;
+
+ body = (struct ggpkt_mod_0_internal *)pkt->body;
+ switch(body->type) {
+ case GGPKT_MOD_0_INTERNAL_HELLO:
+ size = sizeof((struct ggpkt_mod_0_internal *)0)->data.hello;
+ break;
+ case GGPKT_MOD_0_INTERNAL_HELLO_RES:
+ size = sizeof((struct ggpkt_mod_0_internal *)0)->data.hello_res;
+ break;
+ case GGPKT_MOD_0_INTERNAL_AUTH:
+ size = sizeof((struct ggpkt_mod_0_internal *)0)->data.auth \
+ + body->data.auth.probe_password_len;
+ break;
+ case GGPKT_MOD_0_INTERNAL_AUTH_RES:
+ size = sizeof((struct ggpkt_mod_0_internal *)0)->data.auth_res;
+ break;
+ case GGPKT_MOD_0_INTERNAL_NOTICE:
+ size = sizeof((struct ggpkt_mod_0_internal *)0)->data.notice \
+ + body->data.notice.len;
+ break;
+ case GGPKT_MOD_0_INTERNAL_PING:
+ size = sizeof((struct ggpkt_mod_0_internal *)0)->data.ping;
+ break;
+ case GGPKT_MOD_0_INTERNAL_PING_RES:
+ size = sizeof((struct ggpkt_mod_0_internal *)0)->data.ping_res;
+ break;
+ default:
+ size = -1;
+ break;
+ }
+
+ return size;
+}
+
diff --git a/v3/libglouglou/libglouglou_mod_0_internal/libglouglou_mod_0_internal.h b/v3/libglouglou/libglouglou_mod_0_internal/libglouglou_mod_0_internal.h
new file mode 100644
index 0000000..841ef99
--- /dev/null
+++ b/v3/libglouglou/libglouglou_mod_0_internal/libglouglou_mod_0_internal.h
@@ -0,0 +1,64 @@
+#include "../libglouglou.h"
+
+#define GLOUGLOU_PASS_SIZE_MAX 16
+
+#define GGPKT_MOD_0_INTERNAL_ID 0
+#define GGPKT_MOD_0_INTERNAL_VERSION 1
+
+enum ggpkt_mod_0_internal_type {
+ GGPKT_MOD_0_INTERNAL_HELLO = 0x00,
+ GGPKT_MOD_0_INTERNAL_HELLO_RES = 0x01,
+ GGPKT_MOD_0_INTERNAL_AUTH = 0x02,
+ GGPKT_MOD_0_INTERNAL_AUTH_RES = 0x03,
+ GGPKT_MOD_0_INTERNAL_PING = 0x10,
+ GGPKT_MOD_0_INTERNAL_PING_RES = 0x11,
+ GGPKT_MOD_0_INTERNAL_NOTICE = 0x20,
+};
+
+enum ggpkt_mod_0_internal_auth_status {
+ AUTH_STATUS_OK = 0x00,
+ AUTH_STATUS_REFUSED = 0x01,
+};
+
+struct ggpkt_mod_0_internal {
+ struct __attribute__((packed)) ggpkt_header header; /* libglouglou mandatory */
+ u_int8_t type;
+ union {
+ struct __attribute__((packed)) hello {
+ u_int32_t random_probe;
+ } hello;
+ struct __attribute__((packed)) hello_res {
+ u_int32_t random_ggd;
+ } hello_res;
+ struct __attribute__((packed)) auth {
+ u_int16_t probe_id;
+ u_int8_t probe_password_len;
+ char probe_password[GLOUGLOU_PASS_SIZE_MAX];
+ u_int32_t random_probe;
+ u_int32_t random_ggd;
+ } auth;
+ struct __attribute__((packed)) auth_res {
+ u_int8_t status;
+ } auth_res;
+ struct __attribute__((packed)) notice {
+ u_int16_t len;
+ char msg[GGPKT_ARG_MAX];
+ } notice;
+ struct __attribute__((packed)) ping {
+ u_int32_t random;
+ } ping;
+ struct __attribute__((packed)) ping_res {
+ u_int32_t random_res;
+ } ping_res;
+ } data;
+};
+
+struct ggpkt *ggpkt_mod_0_internal_hello(void);
+struct ggpkt *ggpkt_mod_0_internal_hello_res(void);
+struct ggpkt *ggpkt_mod_0_internal_hello_auth(int probe_id, char *pass,
+ int random_probe, int random_ggd);
+struct ggpkt *ggpkt_mod_0_internal_auth_res(int status);
+struct ggpkt *ggpkt_mod_0_internal_notice(char *notice_msg);
+struct ggpkt *ggpkt_mod_0_internal_ping(void);
+struct ggpkt *ggpkt_mod_0_internal_ping_res(int random_res);
+struct ggpkt_mod_0_internal *ggpkt_mod_0_internal_decode(char *buf);
diff --git a/v3/libglouglou/libglouglou_mod_1_net/Makefile b/v3/libglouglou/libglouglou_mod_1_net/Makefile
new file mode 100644
index 0000000..9130cae
--- /dev/null
+++ b/v3/libglouglou/libglouglou_mod_1_net/Makefile
@@ -0,0 +1,16 @@
+# Glougloud module header generic Makefile
+
+PREFIX=/usr/local
+INCLUDEDIR=$(PREFIX)/include/glougloud/modules
+
+HEADERS = $(shell echo *.h)
+
+all:
+ @echo "this package contains headers only,"
+ @echo "run \"make install\" to install it."
+
+install:
+ @echo "headers installation"
+ mkdir -p $(INCLUDEDIR)
+ install -m 0644 $(HEADERS) $(INCLUDEDIR)
+