Signed-off-by: Sven Eckelmann sven@open-mesh.com --- alfred.h | 6 ++---- batadv_query.c | 13 +++++++++---- client.c | 12 +++++------- debugfs.c | 10 ++++------ debugfs.h | 3 --- hash.c | 5 +++-- main.c | 11 ++++------- netsock.c | 14 ++++++++------ recv.c | 21 ++++++++++++--------- send.c | 17 ++++++----------- server.c | 10 ++++++---- unix_sock.c | 14 +++++++++----- util.c | 6 ++++-- vis/vis.c | 15 +++++++++++++++ vis/vis.h | 20 +++----------------- 15 files changed, 90 insertions(+), 87 deletions(-)
diff --git a/alfred.h b/alfred.h index c82483c..a244c64 100644 --- a/alfred.h +++ b/alfred.h @@ -23,12 +23,10 @@ #define SOURCE_VERSION "2013.4.0" #endif
-#include <stdint.h> -#include <linux/if_ether.h> -#include <netinet/ether.h> +#include <net/ethernet.h> #include <netinet/in.h> +#include <stdint.h> #include <time.h> -#include "hash.h" #include "list.h" #include "packet.h"
diff --git a/batadv_query.c b/batadv_query.c index db1aed5..83083a1 100644 --- a/batadv_query.c +++ b/batadv_query.c @@ -20,11 +20,16 @@ */
#include "batadv_query.h" -#include "debugfs.h" -#include <stdio.h> -#include <netinet/ether.h> -#include <stdlib.h> #include <errno.h> +#include <net/ethernet.h> +#include <netinet/ether.h> +#include <netinet/in.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include "debugfs.h"
#define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s" #define DEBUG_TRANSTABLE_GLOBAL "transtable_global" diff --git a/client.c b/client.c index a535f5a..3c1916c 100644 --- a/client.c +++ b/client.c @@ -19,17 +19,15 @@ * */
+#include <ctype.h> +#include <errno.h> +#include <netinet/in.h> +#include <stdint.h> #include <stdio.h> -#include <stdlib.h> -#include <getopt.h> #include <string.h> #include <unistd.h> -#include <errno.h> -#include <arpa/inet.h> -#include <sys/select.h> -#include <sys/time.h> -#include <ctype.h> #include "alfred.h" +#include "packet.h"
int alfred_client_request_data(struct globals *globals) { diff --git a/debugfs.c b/debugfs.c index 5a0431f..e62978b 100644 --- a/debugfs.c +++ b/debugfs.c @@ -19,14 +19,12 @@ */
#include "debugfs.h" -#include <stdio.h> -#include <stdlib.h> #include <errno.h> -#include <sys/vfs.h> -#include <sys/types.h> +#include <stdio.h> +#include <string.h> +#include <sys/mount.h> #include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> +#include <sys/statfs.h>
#ifndef DEBUGFS_MAGIC #define DEBUGFS_MAGIC 0x64626720 diff --git a/debugfs.h b/debugfs.h index 4008c37..6307a9b 100644 --- a/debugfs.h +++ b/debugfs.h @@ -21,9 +21,6 @@ #ifndef __DEBUGFS_H__ #define __DEBUGFS_H__
-#include <sys/mount.h> -#include <string.h> - #ifndef MAX_PATH # define MAX_PATH 256 #endif diff --git a/hash.c b/hash.c index 8d487eb..940a11f 100644 --- a/hash.c +++ b/hash.c @@ -20,8 +20,9 @@ */
-#include <stdio.h> /* NULL */ -#include <stdlib.h> /* free() */ +#include "hash.h" +#include <stdlib.h> +#include <stdio.h> #include "alfred.h"
/* clears the hash */ diff --git a/main.c b/main.c index 86acfb7..4f39948 100644 --- a/main.c +++ b/main.c @@ -19,17 +19,14 @@ * */
+#include <getopt.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> -#include <getopt.h> #include <string.h> -#include <unistd.h> -#include <errno.h> -#include <arpa/inet.h> -#include <sys/select.h> -#include <sys/time.h> -#include <signal.h> #include "alfred.h" +#include "packet.h" +
static void alfred_usage(void) { diff --git a/netsock.c b/netsock.c index 381d9b0..39281af 100644 --- a/netsock.c +++ b/netsock.c @@ -19,17 +19,19 @@ * */
+#include <sys/socket.h> +#include <errno.h> +#include <fcntl.h> +#include <net/if.h> +#include <netinet/in.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <stdlib.h> -#include <netinet/in.h> #include <sys/ioctl.h> -#include <linux/if.h> +#include <sys/socket.h> +#include <unistd.h> #include "alfred.h" #include "batadv_query.h" +#include "packet.h"
const struct in6_addr in6addr_localmcast = {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/recv.c b/recv.c index 7541632..5ed4a62 100644 --- a/recv.c +++ b/recv.c @@ -19,19 +19,22 @@ * */
-#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> #include <errno.h> -#include <stdlib.h> +#include <net/ethernet.h> #include <netinet/in.h> -#include <sys/ioctl.h> -#include <linux/if.h> -#include <linux/if_packet.h> -#include <arpa/inet.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/time.h> +#include <time.h> +#include <unistd.h> #include "alfred.h" #include "batadv_query.h" +#include "hash.h" +#include "list.h" +#include "packet.h"
static int finish_alfred_push_data(struct globals *globals, struct ether_addr mac, diff --git a/send.c b/send.c index d6920f8..607afa1 100644 --- a/send.c +++ b/send.c @@ -19,19 +19,14 @@ * */
-#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <stdlib.h> #include <netinet/in.h> -#include <sys/ioctl.h> -#include <linux/if.h> -#include <linux/if_packet.h> -#include <linux/if_ether.h> -#include <linux/filter.h> +#include <stddef.h> +#include <stdint.h> +#include <string.h> +#include <sys/socket.h> #include "alfred.h" +#include "hash.h" +#include "packet.h"
int announce_master(struct globals *globals) { diff --git a/server.c b/server.c index 02eab42..0d8e6c8 100644 --- a/server.c +++ b/server.c @@ -19,17 +19,19 @@ * */
+#include <errno.h> +#include <net/ethernet.h> +#include <stddef.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <getopt.h> #include <string.h> -#include <unistd.h> -#include <errno.h> -#include <arpa/inet.h> #include <sys/select.h> #include <sys/time.h> +#include <time.h> #include "alfred.h" #include "batadv_query.h" +#include "hash.h"
static int server_compare(void *d1, void *d2) { diff --git a/unix_sock.c b/unix_sock.c index c778a61..8bff2e1 100644 --- a/unix_sock.c +++ b/unix_sock.c @@ -19,17 +19,21 @@ * */
+#include <errno.h> +#include <net/ethernet.h> +#include <netinet/in.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <errno.h> -#include <unistd.h> -#include <arpa/inet.h> -#include <sys/time.h> -#include <sys/types.h> #include <sys/socket.h> +#include <sys/time.h> #include <sys/un.h> +#include <time.h> +#include <unistd.h> #include "alfred.h" +#include "hash.h" +#include "packet.h"
int unix_sock_open_daemon(struct globals *globals, char *path) { diff --git a/util.c b/util.c index 5405c84..3c50964 100644 --- a/util.c +++ b/util.c @@ -19,10 +19,12 @@ * */
-#include <sys/time.h> -#include <time.h> +#include <stddef.h> #include <stdint.h> #include <stdlib.h> +#include <sys/time.h> +#include <time.h> +#include "alfred.h"
int time_diff(struct timespec *tv1, struct timespec *tv2, struct timespec *tvdiff) { diff --git a/vis/vis.c b/vis/vis.c index 3d0c5f0..5247b31 100644 --- a/vis/vis.c +++ b/vis/vis.c @@ -20,6 +20,21 @@ */
#include "vis.h" +#include <dirent.h> +#include <errno.h> +#include <getopt.h> +#include <linux/if.h> +#include <netinet/in.h> +#include <signal.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include "debugfs.h"
char *read_file(char *fname) { diff --git a/vis/vis.h b/vis/vis.h index 3423066..d4a49d0 100644 --- a/vis/vis.h +++ b/vis/vis.h @@ -19,25 +19,11 @@ * */
-#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <getopt.h> -#include <signal.h> -#include <dirent.h> -#include <sys/ioctl.h> -#include <sys/types.h> #include <sys/socket.h> -#include <sys/un.h> -#include <linux/if.h> -#include <netinet/ether.h> -#include <netinet/in.h> -#include "../packet.h" +#include <linux/if_ether.h> +#include <stdint.h> #include "../list.h" -#include "debugfs.h" +#include "../packet.h"
#ifndef SOURCE_VERSION
Signed-off-by: Sven Eckelmann sven@open-mesh.com --- vis/vis.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/vis/vis.c b/vis/vis.c index 5247b31..5e7a109 100644 --- a/vis/vis.c +++ b/vis/vis.c @@ -36,7 +36,7 @@ #include <unistd.h> #include "debugfs.h"
-char *read_file(char *fname) +static char *read_file(char *fname) { FILE *fp; char *buf = NULL; @@ -64,7 +64,7 @@ char *read_file(char *fname) return buf; }
-char *mac_to_str(uint8_t *mac) +static char *mac_to_str(uint8_t *mac) { static char macstr[20]; snprintf(macstr, sizeof(macstr), "%02x:%02x:%02x:%02x:%02x:%02x", @@ -72,7 +72,7 @@ char *mac_to_str(uint8_t *mac) return macstr; }
-uint8_t *str_to_mac(char *str) +static uint8_t *str_to_mac(char *str) { static uint8_t mac[ETH_ALEN]; int ret; @@ -91,7 +91,7 @@ uint8_t *str_to_mac(char *str) return mac; }
-int get_if_mac(char *ifname, uint8_t *mac) +static int get_if_mac(char *ifname, uint8_t *mac) { struct ifreq ifr; int sock; @@ -112,7 +112,7 @@ int get_if_mac(char *ifname, uint8_t *mac) return 0; }
-int get_if_index(struct globals *globals, char *ifname) +static int get_if_index(struct globals *globals, char *ifname) { struct iface_list_entry *i_entry; int i; @@ -143,7 +143,7 @@ int get_if_index(struct globals *globals, char *ifname) return i; }
-int alfred_open_sock(struct globals *globals) +static int alfred_open_sock(struct globals *globals) { struct sockaddr_un addr;
@@ -168,7 +168,7 @@ int alfred_open_sock(struct globals *globals) return 0; }
-int parse_transtable_local(struct globals *globals) +static int parse_transtable_local(struct globals *globals) { char *fbuf; char *lptr, *tptr; @@ -218,7 +218,7 @@ int parse_transtable_local(struct globals *globals) return 0; }
-void clear_lists(struct globals *globals) +static void clear_lists(struct globals *globals) { struct vis_list_entry *v_entry, *v_entry_safe; struct iface_list_entry *i_entry, *i_entry_safe; @@ -300,7 +300,7 @@ err: }
-int parse_orig_list(struct globals *globals) +static int parse_orig_list(struct globals *globals) { char *fbuf; char *lptr, *tptr; @@ -368,7 +368,7 @@ int parse_orig_list(struct globals *globals) return 0; }
-int vis_publish_data(struct globals *globals) +static int vis_publish_data(struct globals *globals) { int len, ret;
@@ -396,7 +396,7 @@ int vis_publish_data(struct globals *globals) return 0; }
-int compile_vis_data(struct globals *globals) +static int compile_vis_data(struct globals *globals) { struct iface_list_entry *i_entry; struct vis_list_entry *v_entry; @@ -424,7 +424,7 @@ int compile_vis_data(struct globals *globals) return 0; }
-int vis_update_data(struct globals *globals) +static int vis_update_data(struct globals *globals) { clear_lists(globals); register_interfaces(globals); @@ -437,7 +437,7 @@ int vis_update_data(struct globals *globals) return 0; }
-int vis_request_data(struct globals *globals) +static int vis_request_data(struct globals *globals) { int ret;
@@ -463,7 +463,7 @@ int vis_request_data(struct globals *globals) }
-struct vis_v1 *vis_receive_answer_packet(int sock, uint16_t *len) +static struct vis_v1 *vis_receive_answer_packet(int sock, uint16_t *len) { static uint8_t buf[65536]; struct alfred_tlv *tlv; @@ -510,7 +510,7 @@ struct vis_v1 *vis_receive_answer_packet(int sock, uint16_t *len) return (struct vis_v1 *) data->data; }
-int vis_read_answer(struct globals *globals) +static int vis_read_answer(struct globals *globals) { struct vis_v1 *vis_data; uint16_t len; @@ -593,7 +593,7 @@ int vis_read_answer(struct globals *globals) return 0; }
-int vis_get_data(struct globals *globals) +static int vis_get_data(struct globals *globals) { globals->unix_sock = vis_request_data(globals); if (globals->unix_sock < 0) @@ -676,7 +676,7 @@ static struct globals *vis_init(int argc, char *argv[])
-int vis_server(struct globals *globals) +static int vis_server(struct globals *globals) { char *debugfs_mnt;
On Mon, Sep 09, 2013 at 05:46:02PM +0200, Sven Eckelmann wrote:
Signed-off-by: Sven Eckelmann sven@open-mesh.com
vis/vis.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
Applied in revision 65aee8d.
Thanks, Simon
Signed-off-by: Sven Eckelmann sven@open-mesh.com --- alfred.h | 8 ++++---- batadv_query.c | 6 +++--- batadv_query.h | 6 +++--- debugfs.c | 3 ++- debugfs.h | 2 +- unix_sock.c | 4 ++-- vis/vis.h | 2 +- 7 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/alfred.h b/alfred.h index a244c64..e44919c 100644 --- a/alfred.h +++ b/alfred.h @@ -91,8 +91,8 @@ struct globals { struct in6_addr address; uint32_t scope_id; struct server *best_server; /* NULL if we are a server ourselves */ - char *interface; - char *mesh_iface; + const char *interface; + const char *mesh_iface; enum opmode opmode; enum clientmode clientmode; int clientmode_arg; @@ -139,8 +139,8 @@ int send_alfred_packet(struct globals *globals, const struct in6_addr *dest, void *buf, int length); /* unix_sock.c */ int unix_sock_read(struct globals *globals); -int unix_sock_open_daemon(struct globals *globals, char *path); -int unix_sock_open_client(struct globals *globals, char *path); +int unix_sock_open_daemon(struct globals *globals, const char *path); +int unix_sock_open_client(struct globals *globals, const char *path); int unix_sock_close(struct globals *globals); int unix_sock_req_data_finish(struct globals *globals, struct transaction_head *head); diff --git a/batadv_query.c b/batadv_query.c index 83083a1..f1e3f24 100644 --- a/batadv_query.c +++ b/batadv_query.c @@ -88,7 +88,7 @@ int ipv6_to_mac(const struct in6_addr *addr, struct ether_addr *mac) return 0; }
-int batadv_interface_check(char *mesh_iface) +int batadv_interface_check(const char *mesh_iface) { char *debugfs_mnt; char full_path[MAX_PATH+1]; @@ -125,7 +125,7 @@ int batadv_interface_check(char *mesh_iface) return 0; }
-struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac) +struct ether_addr *translate_mac(const char *mesh_iface, struct ether_addr *mac) { enum { tg_start, @@ -207,7 +207,7 @@ out: return mac_result; }
-uint8_t get_tq(char *mesh_iface, struct ether_addr *mac) +uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac) { enum { orig_mac, diff --git a/batadv_query.h b/batadv_query.h index 7dca319..5ab6f3e 100644 --- a/batadv_query.h +++ b/batadv_query.h @@ -24,9 +24,9 @@ #include <stdint.h> #include <netinet/in.h>
-struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac); -uint8_t get_tq(char *mesh_iface, struct ether_addr *mac); -int batadv_interface_check(char *mesh_iface); +struct ether_addr *translate_mac(const char *mesh_iface, struct ether_addr *mac); +uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac); +int batadv_interface_check(const char *mesh_iface); int mac_to_ipv6(const struct ether_addr *mac, struct in6_addr *addr); int ipv6_to_mac(const struct in6_addr *addr, struct ether_addr *mac); int is_ipv6_eui64(const struct in6_addr *addr); diff --git a/debugfs.c b/debugfs.c index e62978b..1e9418d 100644 --- a/debugfs.c +++ b/debugfs.c @@ -43,7 +43,8 @@ static const char *debugfs_known_mountpoints[] = { };
/* construct a full path to a debugfs element */ -int debugfs_make_path(const char *fmt, char *mesh_iface, char *buffer, int size) +int debugfs_make_path(const char *fmt, const char *mesh_iface, char *buffer, + int size) { int len;
diff --git a/debugfs.h b/debugfs.h index 6307a9b..b4dc6bb 100644 --- a/debugfs.h +++ b/debugfs.h @@ -32,7 +32,7 @@
extern int debugfs_valid_entry(const char *path); extern char *debugfs_mount(const char *mountpoint); -extern int debugfs_make_path(const char *fmt, char *mesh_iface, +extern int debugfs_make_path(const char *fmt, const char *mesh_iface, char *buffer, int size);
#endif /* __DEBUGFS_H__ */ diff --git a/unix_sock.c b/unix_sock.c index 8bff2e1..6b80f38 100644 --- a/unix_sock.c +++ b/unix_sock.c @@ -35,7 +35,7 @@ #include "hash.h" #include "packet.h"
-int unix_sock_open_daemon(struct globals *globals, char *path) +int unix_sock_open_daemon(struct globals *globals, const char *path) { struct sockaddr_un addr;
@@ -68,7 +68,7 @@ int unix_sock_open_daemon(struct globals *globals, char *path) return 0; }
-int unix_sock_open_client(struct globals *globals, char *path) +int unix_sock_open_client(struct globals *globals, const char *path) { struct sockaddr_un addr;
diff --git a/vis/vis.h b/vis/vis.h index d4a49d0..6ba70c6 100644 --- a/vis/vis.h +++ b/vis/vis.h @@ -89,7 +89,7 @@ struct vis_list_entry { + (vis_data)->entries_n * sizeof(struct vis_entry))
struct globals { - char *interface; + const char *interface; enum opmode opmode; enum vis_format vis_format; uint8_t buf[65536];
On Mon, Sep 09, 2013 at 05:46:03PM +0200, Sven Eckelmann wrote:
Signed-off-by: Sven Eckelmann sven@open-mesh.com
alfred.h | 8 ++++---- batadv_query.c | 6 +++--- batadv_query.h | 6 +++--- debugfs.c | 3 ++- debugfs.h | 2 +- unix_sock.c | 4 ++-- vis/vis.h | 2 +- 7 files changed, 16 insertions(+), 15 deletions(-)
Applied in revision 669fb47.
Thanks, Simon
Signed-off-by: Sven Eckelmann sven@open-mesh.com --- client.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/client.c b/client.c index 3c1916c..2187ff2 100644 --- a/client.c +++ b/client.c @@ -81,6 +81,9 @@ int alfred_client_request_data(struct globals *globals) ret = read(globals->unix_sock, buf + sizeof(*push), sizeof(*data));
+ if (ret < (ssize_t)sizeof(*data)) + break; + data = push->data; data_len = ntohs(data->header.length);
On Mon, Sep 09, 2013 at 05:46:04PM +0200, Sven Eckelmann wrote:
Signed-off-by: Sven Eckelmann sven@open-mesh.com
client.c | 3 +++ 1 file changed, 3 insertions(+)
Applied in revision 6a2276c.
Thanks, Simon
Signed-off-by: Sven Eckelmann sven@open-mesh.com --- unix_sock.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/unix_sock.c b/unix_sock.c index 6b80f38..e6b22e8 100644 --- a/unix_sock.c +++ b/unix_sock.c @@ -310,8 +310,6 @@ int unix_sock_read(struct globals *globals) if (packet->version != ALFRED_VERSION) goto err;
- ret = 0; - switch (packet->type) { case ALFRED_PUSH_DATA: ret = unix_sock_add_data(globals,
On Mon, Sep 09, 2013 at 05:46:05PM +0200, Sven Eckelmann wrote:
Signed-off-by: Sven Eckelmann sven@open-mesh.com
unix_sock.c | 2 -- 1 file changed, 2 deletions(-)
Applied in revision a66dc45.
Thanks, Simon
Signed-off-by: Sven Eckelmann sven@open-mesh.com --- vis/vis.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/vis/vis.c b/vis/vis.c index 5e7a109..36ea7fe 100644 --- a/vis/vis.c +++ b/vis/vis.c @@ -59,7 +59,8 @@ static char *read_file(char *fname) } fclose(fp);
- buf[size] = 0; + if (buf) + buf[size] = 0;
return buf; }
On Mon, Sep 09, 2013 at 05:46:06PM +0200, Sven Eckelmann wrote:
Signed-off-by: Sven Eckelmann sven@open-mesh.com
vis/vis.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Applied in revision 1606d72.
Thanks, Simon
The running daemon may need to be switched between from master to slave mode or from slave to master mode to increase the efficiency of the data distribution network. This must be possible during runtime to avoid the data loss during the switch time.
Signed-off-by: Sven Eckelmann sven@open-mesh.com --- alfred.h | 2 ++ client.c | 38 ++++++++++++++++++++++++++++++++++++++ main.c | 19 ++++++++++++++++++- packet.h | 24 ++++++++++++++++++++++++ unix_sock.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-)
diff --git a/alfred.h b/alfred.h index e44919c..e931b1b 100644 --- a/alfred.h +++ b/alfred.h @@ -84,6 +84,7 @@ enum clientmode { CLIENT_NONE, CLIENT_REQUEST_DATA, CLIENT_SET_DATA, + CLIENT_MODESWITCH, };
struct globals { @@ -119,6 +120,7 @@ int set_best_server(struct globals *globals); /* client.c */ int alfred_client_request_data(struct globals *globals); int alfred_client_set_data(struct globals *globals); +int alfred_client_modeswitch(struct globals *globals); /* recv.c */ int recv_alfred_packet(struct globals *globals); struct transaction_head * diff --git a/client.c b/client.c index 2187ff2..4bc7b5c 100644 --- a/client.c +++ b/client.c @@ -179,3 +179,41 @@ int alfred_client_set_data(struct globals *globals) unix_sock_close(globals); return 0; } + +int alfred_client_modeswitch(struct globals *globals) +{ + unsigned char buf[MAX_PAYLOAD]; + struct alfred_modeswitch_v0 *modeswitch; + int ret, len; + + if (unix_sock_open_client(globals, ALFRED_SOCK_PATH)) + return -1; + + modeswitch = (struct alfred_modeswitch_v0 *)buf; + len = sizeof(*modeswitch); + + modeswitch->header.type = ALFRED_MODESWITCH; + modeswitch->header.version = ALFRED_VERSION; + modeswitch->header.length = htons(len - sizeof(modeswitch->header)); + + switch (globals->opmode) { + case OPMODE_SLAVE: + modeswitch->mode = ALFRED_MODESWITCH_SLAVE; + break; + case OPMODE_MASTER: + modeswitch->mode = ALFRED_MODESWITCH_MASTER; + break; + default: + fprintf(stderr, "%s: unknown opmode %u in modeswitch\n", + __func__, globals->opmode); + return -1; + } + + ret = write(globals->unix_sock, buf, len); + if (ret != len) + fprintf(stderr, "%s: only wrote %d of %d bytes: %s\n", + __func__, ret, len, strerror(errno)); + + unix_sock_close(globals); + return 0; +} diff --git a/main.c b/main.c index 4f39948..4cc8aa4 100644 --- a/main.c +++ b/main.c @@ -37,6 +37,8 @@ static void alfred_usage(void) printf(" -r, --request [data type] collect data from the network and prints\n"); printf(" it on the network\n"); printf(" -V, --req-version specify the data version set for -s\n"); + printf(" -M, --modeswitch master switch daemon to mode master"); + printf(" slave switch daemon to mode slave"); printf("\n"); printf("server mode options:\n"); printf(" -i, --interface specify the interface to listen on\n"); @@ -62,6 +64,7 @@ static struct globals *alfred_init(int argc, char *argv[]) {"master", no_argument, NULL, 'm'}, {"help", no_argument, NULL, 'h'}, {"req-version", required_argument, NULL, 'V'}, + {"modeswitch", required_argument, NULL, 'M'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}, }; @@ -81,7 +84,7 @@ static struct globals *alfred_init(int argc, char *argv[])
time_random_seed();
- while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:", long_options, + while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:", long_options, &opt_ind)) != -1) { switch (opt) { case 'r': @@ -120,6 +123,17 @@ static struct globals *alfred_init(int argc, char *argv[]) } globals->clientmode_version = atoi(optarg); break; + case 'M': + if (strcmp(optarg, "master") == 0) { + globals->opmode = OPMODE_MASTER; + } else if (strcmp(optarg, "slave") == 0) { + globals->opmode = OPMODE_SLAVE; + } else { + fprintf(stderr, "bad modeswitch argument\n"); + return NULL; + } + globals->clientmode = CLIENT_MODESWITCH; + break; case 'v': printf("%s %s\n", argv[0], SOURCE_VERSION); printf("A.L.F.R.E.D. - Almighty Lightweight Remote Fact Exchange Daemon\n"); @@ -155,6 +169,9 @@ int main(int argc, char *argv[]) case CLIENT_SET_DATA: return alfred_client_set_data(globals); break; + case CLIENT_MODESWITCH: + return alfred_client_modeswitch(globals); + break; }
return 0; diff --git a/packet.h b/packet.h index 57fa471..8250c9c 100644 --- a/packet.h +++ b/packet.h @@ -66,6 +66,7 @@ struct alfred_transaction_mgmt { * @ALFRED_REQUEST: Packet is an alfred_request_v* * @ALFRED_STATUS_TXEND: Transaction was finished by sender * @ALFRED_STATUS_ERROR: Error was detected during the transaction + * @ALFRED_MODESWITCH: Switch between different operation modes */ enum alfred_packet_type { ALFRED_PUSH_DATA = 0, @@ -73,6 +74,7 @@ enum alfred_packet_type { ALFRED_REQUEST = 2, ALFRED_STATUS_TXEND = 3, ALFRED_STATUS_ERROR = 4, + ALFRED_MODESWITCH = 5, };
/* packets */ @@ -119,6 +121,28 @@ struct alfred_request_v0 { } __packed;
/** + * enum alfred_modeswitch_type - Mode of the daemon + * @ALFRED_MODESWITCH_SLAVE: see OPMODE_SLAVE + * @ALFRED_MODESWITCH_MASTER: see OPMODE_MASTER + */ +enum alfred_modeswitch_type { + ALFRED_MODESWITCH_SLAVE = 0, + ALFRED_MODESWITCH_MASTER = 1, +}; + +/** + * struct alfred_modeswitch_v0 - Request for a specific type + * @header: TLV header describing the complete packet + * @mode: data type which is requested + * + * Sent to the daemon by client + */ +struct alfred_modeswitch_v0 { + struct alfred_tlv header; + uint8_t mode; +} __packed; + +/** * struct alfred_status_v0 - Status info of a transaction * @header: TLV header describing the complete packet * @tx: Transaction identificator and sequence number of packet diff --git a/unix_sock.c b/unix_sock.c index e6b22e8..3738d6d 100644 --- a/unix_sock.c +++ b/unix_sock.c @@ -272,6 +272,34 @@ int unix_sock_req_data_finish(struct globals *globals, return ret; }
+static int unix_sock_modesw(struct globals *globals, + struct alfred_modeswitch_v0 *modeswitch, + int client_sock) +{ + int len, ret = -1; + + len = ntohs(modeswitch->header.length); + + if (len < (int)(sizeof(*modeswitch) - sizeof(modeswitch->header))) + goto err; + + switch (modeswitch->mode) { + case ALFRED_MODESWITCH_SLAVE: + globals->opmode = OPMODE_SLAVE; + break; + case ALFRED_MODESWITCH_MASTER: + globals->opmode = OPMODE_MASTER; + break; + default: + goto err; + } + + ret = 0; +err: + close(client_sock); + return ret; +} + int unix_sock_read(struct globals *globals) { int client_sock; @@ -321,6 +349,11 @@ int unix_sock_read(struct globals *globals) (struct alfred_request_v0 *)packet, client_sock); break; + case ALFRED_MODESWITCH: + ret = unix_sock_modesw(globals, + (struct alfred_modeswitch_v0 *)packet, + client_sock); + break; default: /* unknown packet type */ ret = -1;
On Mon, Sep 09, 2013 at 05:46:07PM +0200, Sven Eckelmann wrote:
The running daemon may need to be switched between from master to slave mode or from slave to master mode to increase the efficiency of the data distribution network. This must be possible during runtime to avoid the data loss during the switch time.
Signed-off-by: Sven Eckelmann sven@open-mesh.com
alfred.h | 2 ++ client.c | 38 ++++++++++++++++++++++++++++++++++++++ main.c | 19 ++++++++++++++++++- packet.h | 24 ++++++++++++++++++++++++ unix_sock.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-)
Applied in revision 06ce1cc with minor modifications (added newlines to usage text).
Thanks, Simon
On Mon, Sep 09, 2013 at 05:46:01PM +0200, Sven Eckelmann wrote:
Signed-off-by: Sven Eckelmann sven@open-mesh.com
alfred.h | 6 ++---- batadv_query.c | 13 +++++++++---- client.c | 12 +++++------- debugfs.c | 10 ++++------ debugfs.h | 3 --- hash.c | 5 +++-- main.c | 11 ++++------- netsock.c | 14 ++++++++------ recv.c | 21 ++++++++++++--------- send.c | 17 ++++++----------- server.c | 10 ++++++---- unix_sock.c | 14 +++++++++----- util.c | 6 ++++-- vis/vis.c | 15 +++++++++++++++ vis/vis.h | 20 +++----------------- 15 files changed, 90 insertions(+), 87 deletions(-)
Applied in revision 5599105.
Thanks, Simon
b.a.t.m.a.n@lists.open-mesh.org