Skip to content

Commit 6d5e639

Browse files
author
chris
committed
o Fix bug with first try failing with IPC (was invalid length
initialization to recvfrom). o Update lispmanager a bit for just using lispd with no module. o Add retries to lispconf and timeouts so it won't hang.
1 parent 676f3f6 commit 6d5e639

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

lispd_tuntap/lispconf/lispconf.c

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,27 @@ int send_command(lisp_cmd_t *cmd, int length)
4949
{
5050

5151
int retval;
52-
53-
printf("Cmd: 0x%x, cmd->length: %d", cmd, cmd->length);
54-
if ((retval = sendto(dsock_fd, cmd, sizeof(lisp_cmd_t) + cmd->length, 0,
55-
(struct sockaddr*)&server_sock, sizeof(struct sockaddr_un)) < 0)) {
52+
int retries = 2;
53+
struct timeval tv;
54+
55+
tv.tv_sec = 1; /* 1 second timeout */
56+
tv.tv_usec = 0;
57+
58+
setsockopt(dsock_fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval));
59+
while (retries) {
60+
if ((retval = sendto(dsock_fd, cmd, sizeof(lisp_cmd_t) + cmd->length, 0,
61+
(struct sockaddr*)&server_sock, sizeof(struct sockaddr_un)) < 0)) {
62+
retries--;
63+
printf("timeout error, retrying...");
64+
} else {
65+
break;
66+
}
67+
}
68+
if (!retries) {
5669
printf("Failed to send message, errno %d (%s)", errno, strerror(errno));
5770
exit(-1);
5871
}
72+
5973
return retval;
6074
}
6175

@@ -262,6 +276,11 @@ int process_print_cache_responses(void)
262276
char *formatted_rloc = NULL;
263277
struct timeval uptime;
264278
struct timeval expiretime;
279+
int retries = 2;
280+
struct timeval tv;
281+
282+
tv.tv_sec = 1; /* 1 second timeout */
283+
tv.tv_usec = 0;
265284

266285
if (!cmd) {
267286
printf("Memory allocation failure\n");
@@ -270,15 +289,15 @@ int process_print_cache_responses(void)
270289

271290
printf("LISP IP Mapping Cache\n\n");
272291

292+
293+
setsockopt(dsock_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));
273294
while (1) {
274295
if ((retval = recvfrom(dsock_fd, cmd, MAX_MSG_LENGTH, 0, (struct sockaddr *)&server_sock,
275296
&addr_len)) < 0) {
276-
perror("recv");
277297
break;
278298
}
279299
if (!retval) {
280-
printf("Peer closed connection.");
281-
break;
300+
return(errno);
282301
}
283302
map_msg = (lisp_cache_response_msg_t *)cmd->val;
284303
if (cmd->type == LispOk) {
@@ -602,6 +621,7 @@ int send_print_command(struct gengetopt_args_info *args_info)
602621
lisp_cmd_t *cmd;
603622
int cmd_length = sizeof(lisp_cmd_t) + sizeof(lisp_lookup_msg_t);
604623
int retval;
624+
int retries = 2;
605625
lisp_addr_t eid_prefix;
606626
int eid_prefix_len;
607627
int eid_af;
@@ -689,10 +709,21 @@ int send_print_command(struct gengetopt_args_info *args_info)
689709

690710
retval = send_command(cmd, cmd_length);
691711

692-
if (cache) {
693-
process_print_cache_responses();
694-
} else {
695-
process_print_db_responses();
712+
while (retries) {
713+
if (cache) {
714+
retval = process_print_cache_responses();
715+
} else {
716+
retval = process_print_db_responses();
717+
}
718+
if (retval == ETIMEDOUT) {
719+
retries--;
720+
continue;
721+
} else {
722+
if (retval != 0) {
723+
printf("Error waiting for response from lispd: %d", errno);
724+
}
725+
break;
726+
}
696727
}
697728
return retval;
698729
}

lispd_tuntap/lispd_ipc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ static void wait_for_completion()
109109
static void * handle_ipc_requests(void *arg)
110110
{
111111
struct sockaddr_un sock_addr;
112-
socklen_t sock_len;
113-
struct msghdr msg;
114-
struct iovec v;
112+
socklen_t sock_len = sizeof(struct sockaddr_un);
115113
lisp_cmd_t *cmd = malloc(MaxIPCCommandLen);
116114

117115
if (!cmd) {
@@ -269,7 +267,7 @@ int send_cache_lookup_response_msg(lisp_map_cache_t *entry)
269267
log_msg(INFO, " Sending response.");
270268
err = send_message(cmd);
271269
if (err < 0)
272-
log_msg(INFO, " netlink_unicast() returned %d\n", err);
270+
log_msg(INFO, " send_message() returned %d\n", err);
273271
free(cmd);
274272
return 0;
275273
}

lispd_tuntap/lispmanager/lispmanager.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const char *moduleRemoveCommand = "/system/bin/rmmod";
2727
const char *killCommand = "/system/bin/kill -15";
2828
const char *lockFilename = "/sdcard/lispd.lock";
2929
const char *moduleCheckFilename = "/proc/modules";
30-
const char *procCheckCommand = "/system/xbin/pgrep -l lispd";
30+
const char *procCheckCommand = "/system/xbin/pgrep -nl lispd";
3131

3232
int startDaemon(void)
3333
{
@@ -70,30 +70,8 @@ int removeKernelMod(void)
7070

7171
void getStatus(void)
7272
{
73-
FILE *procModFile;
7473
FILE *procPipe;
7574
char statusString[128];
76-
char found = 0;
77-
char status = 0;
78-
79-
procModFile = fopen(moduleCheckFilename, "r");
80-
81-
while (!feof(procModFile)) {
82-
fread(statusString, 128, 1, procModFile);
83-
if (strstr(statusString, "lisp")) {
84-
printf("Kernel module: loaded.\n");
85-
found = 1;
86-
}
87-
}
88-
89-
if (!found) {
90-
printf("Kernel module: not loaded.\n");
91-
printf("lispd: not running.\n");
92-
status = 2;
93-
exit(status);
94-
}
95-
96-
found = 0;
9775

9876
procPipe = popen(procCheckCommand, "r");
9977

@@ -105,12 +83,11 @@ void getStatus(void)
10583
fgets(statusString, 128, procPipe);
10684
if (strstr(statusString, "lispd")) {
10785
printf("lispd: running.\n");
108-
exit(status);
86+
exit(0);
10987
}
11088

11189
printf("lispd: not running.\n");
112-
status = 1;
113-
exit(status);
90+
exit(1);
11491
}
11592

11693
int main(int argc, char **argv)

0 commit comments

Comments
 (0)