alfred: Add missing includes and remove unused includes
PATCH 1/7 alfred: Add missing includes and remove unused includes
--- 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(-)
alfred.h +2 -4
@@ -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"
batadv_query.c +9 -4
@@ -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"
client.c +5 -7
@@ -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) {
debugfs.c +4 -6
@@ -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
debugfs.h +0 -3
@@ -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
hash.c +3 -2
@@ -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 */
main.c +4 -7
@@ -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 ) {
netsock.c +8 -6
@@ -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 ,
recv.c +12 -9
@@ -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,
send.c +6 -11
@@ -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) {
server.c +6 -4
@@ -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) {
unix_sock.c +9 -5
@@ -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) {
util.c +4 -2
@@ -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) {
vis/vis.c +15 -0
@@ -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) {
vis/vis.h +3 -17
@@ -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
Signature · 1 line
1.8.4.rc3
PATCH 2/7 alfred: Mark all local functions as static
--- vis/vis.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
vis/vis.c +17 -17
@@ -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;
Signature · 1 line
1.8.4.rc3
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 2/7] alfred: Mark all local functions as static
Quoted 4 lines · Sven Eckelmann
Signed-off-by Sven Eckelmann <[email protected]>--- vis/vis.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
Applied in revision 65aee8d.
Thanks,
Simon
Quoted 1 line
PATCH 3/7 alfred: Fix warning about assigning const to non-const
In reply to Sven Eckelmann--- 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(-)
alfred.h +4 -4
@@ -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);
batadv_query.c +3 -3
@@ -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,
batadv_query.h +3 -3
@@ -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);
debugfs.c +2 -1
@@ -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;
debugfs.h +1 -1
@@ -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__ */
unix_sock.c +2 -2
@@ -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;
vis/vis.h +1 -1
@@ -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 ];
Signature · 1 line
1.8.4.rc3
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 3/7] alfred: Fix warning about assigning const to non-const
Quoted 11 lines · Sven Eckelmann
Signed-off-by Sven Eckelmann <[email protected]>--- 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
PATCH 4/7 alfred: Stop client when data header could not be read
In reply to Sven Eckelmann--- client.c | 3 +++ 1 file changed, 3 insertions(+)
client.c +3 -0
@@ -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);
Signature · 1 line
1.8.4.rc3
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 4/7] alfred: Stop client when data header could not be read
Quoted 5 lines · Sven Eckelmann
Signed-off-by Sven Eckelmann <[email protected]>--- client.c | 3 +++ 1 file changed, 3 insertions(+)
Applied in revision 6a2276c.
Thanks,
Simon
PATCH 5/7 alfred: Remove dead assignment in unix_sock_read
In reply to Sven Eckelmann--- unix_sock.c | 2 -- 1 file changed, 2 deletions(-)
unix_sock.c +0 -2
@@ -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,
Signature · 1 line
1.8.4.rc3
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 5/7] alfred: Remove dead assignment in unix_sock_read
Quoted 5 lines · Sven Eckelmann
Signed-off-by Sven Eckelmann <[email protected]>--- unix_sock.c | 2 -- 1 file changed, 2 deletions(-)
Applied in revision a66dc45.
Thanks,
Simon
PATCH 6/7 alfred: Fix crash when vis opened empty file
In reply to Sven Eckelmann--- vis/vis.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
vis/vis.c +2 -1
@@ -59,7 +59,8 @@ static char *read_file(char *fname) }fclose (fp); - buf[size] =0 ; +if (buf) + buf[size] =0 ;return buf; }
Signature · 1 line
1.8.4.rc3
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 6/7] alfred: Fix crash when vis opened empty file
Quoted 5 lines · Sven Eckelmann
Signed-off-by Sven Eckelmann <[email protected]>--- vis/vis.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Applied in revision 1606d72.
Thanks,
Simon
PATCH 7/7 alfred: Allow to switch daemon between slave and master
In reply to Sven EckelmannThe 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.
--- alfred.h | 2 ++ client.c | 38 ++++++++++++++++++++++++++++++++++++++ main.c | 19 ++++++++++++++++++- packet.h | 24 ++++++++++++++++++++++++ unix_sock.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-)
alfred.h +2 -0
@@ -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 *
client.c +38 -0
@@ -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 ; +}
main.c +18 -1
@@ -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 ;
packet.h +24 -0
@@ -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
unix_sock.c +33 -0
@@ -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 ;
Signature · 1 line
1.8.4.rc3
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 7/7] alfred: Allow to switch daemon between slave and master
Quoted 5 lines · Sven Eckelmann
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.
Quoted 9 lines
Signed-off-by Sven Eckelmann <[email protected]>--- 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
Simon Wunderlich
AppliedQuoted 10 lines · Sven Eckelmann
Signed-off-by Sven Eckelmann <[email protected]>--- 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 ++++++++------
Quoted 8 lines
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