summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQiuwen Lu <[email protected]>2017-10-31 12:51:45 +0800
committerQiuwen Lu <[email protected]>2017-10-31 12:51:45 +0800
commit6e59c3209be1b7a6a8ac6cb8a4e8b6278baf8290 (patch)
tree0e9256b0cfeeb29128dadd9ff86cbb28d4efd31b
parent0292bd0cf7649dce1ff67456aa9d9af0d9afbe97 (diff)
修正免费ARP在不启用ARP功能设备上也发送ARP报文的Bug。
-rw-r--r--app/src/marsio.c81
1 files changed, 43 insertions, 38 deletions
diff --git a/app/src/marsio.c b/app/src/marsio.c
index d4a1692..211b341 100644
--- a/app/src/marsio.c
+++ b/app/src/marsio.c
@@ -253,56 +253,56 @@ static int mrapp_bpf_dumper_init(struct mr_instance * instance, struct mr_vdev *
}
-static unsigned __table_strip(char *str, unsigned len)
-{
- int newlen = len;
- if (len == 0)
- return 0;
-
+static unsigned __table_strip(char *str, unsigned len)
+{
+ int newlen = len;
+ if (len == 0)
+ return 0;
+
if (isspace(str[len - 1]))
- {
- /* strip trailing whitespace */
- while (newlen > 0 && isspace(str[newlen - 1]))
- str[--newlen] = '\0';
- }
-
+ {
+ /* strip trailing whitespace */
+ while (newlen > 0 && isspace(str[newlen - 1]))
+ str[--newlen] = '\0';
+ }
+
if (isspace(str[0]))
- {
- /* strip leading whitespace */
- int i, start = 1;
- while (isspace(str[start]) && start < newlen)
- start++
- ; /* do nothing */
- newlen -= start;
- for (i = 0; i < newlen; i++)
- str[i] = str[i + start];
- str[i] = '\0';
- }
-
- return newlen;
-}
+ {
+ /* strip leading whitespace */
+ int i, start = 1;
+ while (isspace(str[start]) && start < newlen)
+ start++
+ ; /* do nothing */
+ newlen -= start;
+ for (i = 0; i < newlen; i++)
+ str[i] = str[i + start];
+ str[i] = '\0';
+ }
+
+ return newlen;
+}
static const char * __table_readline(FILE * fp, char * buffer,
size_t sz_buffer, size_t * buffer_len, unsigned int * line_no)
{
while (fgets(buffer, sz_buffer, fp) != NULL)
{
- char *pos = NULL;
+ char *pos = NULL;
size_t len = strnlen(buffer, sz_buffer);
(*line_no)++;
-
+
if ((len >= sizeof(buffer) - 1) && (buffer[len - 1] != '\n'))
{
- continue;
+ continue;
}
-
- pos = memchr(buffer, '#', sz_buffer);
+
+ pos = memchr(buffer, '#', sz_buffer);
if (pos != NULL)
- {
- *pos = '\0';
- len = pos - buffer;
- }
-
+ {
+ *pos = '\0';
+ len = pos - buffer;
+ }
+
len = __table_strip(buffer, len);
if (len == 0)
{
@@ -499,8 +499,13 @@ static int mrapp_neigh_device_init(struct mr_instance * instance, struct mr_vdev
__neigh_entry_iter->str_ether_addr, __neigh_entry_iter->devsym);
}
- /* 设备开启了发送队列后,发免费ARP报文 */
- for (int i = 0; vdev->nr_txstream > 0 && i < instance->nr_gratuitous_arp_send; i++)
+ /* 设备开启了发送队列后,且启用了ARP功能,发免费ARP报文 */
+ if (vdev->nr_txstream == 0 || vdev->en_arp == 0)
+ {
+ return RT_SUCCESS;
+ }
+
+ for (int i = 0; i < instance->nr_gratuitous_arp_send; i++)
{
arp_request_send(vdev->vdi, 0, vdev->vdi->vdev->in_addr);
}