Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void alternate_fd()
{
char numstr[10];
alternate_stdin=open("/dev/null",O_RDONLY);
alternate_stdout=open("/dev/null",O_RDONLY);
alternate_stdout=open("/dev/null",O_WRONLY);
close(alternate_stdin);
close(alternate_stdout);
snprintf(numstr,10,"%d",alternate_stdin);
Expand Down
7 changes: 4 additions & 3 deletions src/vde_autolink.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,15 @@ void insert_job(void (*f)(struct autolink *al), struct autolink *al, int gap)

/* remove other jobs for same alink, if any */
while(j){
struct job *next = j->n;
if (al == j->al) {
if (jq == j) jq=j->n;
else pj->n=j->n;
free(j);
}
pj = j;
j = j->n;
else
pj = j;
j = next;
}

/* insert job, ordered by time */
Expand Down Expand Up @@ -1475,4 +1477,3 @@ int main(int argc,char **argv)

}
}

2 changes: 1 addition & 1 deletion src/vde_plug2tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ int main(int argc, char **argv)
}

for(;;) {
poll(pollv,3,-1);
poll(pollv,npollv,-1);
if ((pollv[0].revents | pollv[1].revents | pollv[2].revents) & POLLHUP ||
(npollv > 2 && pollv[2].revents & POLLIN))
break;
Comment thread
danielinux marked this conversation as resolved.
Outdated
Expand Down
42 changes: 8 additions & 34 deletions src/vde_router/vder_arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,14 @@ int vder_parse_arp(struct vder_iface *vif, struct vde_buff *vdb)
struct vder_arp_entry *vder_arp_get_record_by_macaddr(struct vder_iface *vif, uint8_t *mac)
{
struct rb_node *node;
struct vder_arp_entry *found=NULL;
node = vif->arp_table.rb_node;
while(node) {
struct vder_arp_entry *entry = rb_entry(node, struct vder_arp_entry, rb_node);
if (memcmp(entry->macaddr, mac, ETHERNET_ADDRESS_SIZE) == 0) {
found = entry;
break;
}
node = node->rb_left;
}
if (found)
return found;
node = vif->arp_table.rb_node;
while(node) {

for (node = rb_first(&vif->arp_table); node; node = rb_next(node)) {
struct vder_arp_entry *entry = rb_entry(node, struct vder_arp_entry, rb_node);
if (memcmp(entry->macaddr, mac, ETHERNET_ADDRESS_SIZE) == 0) {
found = entry;
break;
}
node = node->rb_right;
if (memcmp(entry->macaddr, mac, ETHERNET_ADDRESS_SIZE) == 0)
return entry;
}
return found;

return NULL;
}

int vder_arp_get_neighbors(struct vder_iface *vif, uint32_t *neighbors, int vector_size)
Expand All @@ -167,24 +153,12 @@ int vder_arp_get_neighbors(struct vder_iface *vif, uint32_t *neighbors, int vect
if (vector_size <= 0)
return -EINVAL;

node = vif->arp_table.rb_node;
while(node) {
for (node = rb_first(&vif->arp_table); node; node = rb_next(node)) {
struct vder_arp_entry *entry = rb_entry(node, struct vder_arp_entry, rb_node);
neighbors[i++] = entry->ipaddr;
if (i == vector_size)
return i;
node = node->rb_left;
}
node = vif->arp_table.rb_node;
if (!node)
return i;
node = node->rb_right;
while(node) {
struct vder_arp_entry *entry = rb_entry(node, struct vder_arp_entry, rb_node);
neighbors[i++] = entry->ipaddr;
if (i == vector_size)
return i;
node = node->rb_right;
}

return i;
}
4 changes: 3 additions & 1 deletion src/vde_router/vder_datalink.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ int vder_iface_address_del(struct vder_iface *iface, uint32_t addr)
uint32_t netmask = 0U;
pthread_mutex_lock(&Router.global_config_lock);
while(cur) {
struct vder_ip4address *next = cur->next;
if (cur->address == addr) {
if (prev) {
prev->next = cur->next;
Expand All @@ -404,9 +405,10 @@ int vder_iface_address_del(struct vder_iface *iface, uint32_t addr)
}
netmask = cur->netmask;
free(cur);
break;
}
prev = cur;
cur = cur->next;
cur = next;
}
pthread_mutex_unlock(&Router.global_config_lock);

Expand Down
2 changes: 1 addition & 1 deletion src/vde_router/vder_dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static uint8_t dhcp_get_next_option(uint8_t *begin, uint8_t *data, int *len, uin
*nextopt = ++p;
if ((type == DHCPOPT_END) || (type == DHCPOPT_PAD)) {
memset(data, 0, *len);
len = 0;
*len = 0;
return type;
}
opt_len = *p;
Expand Down
32 changes: 19 additions & 13 deletions src/vde_router/vder_icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,27 @@ int vder_icmp_filter(uint32_t dst, uint8_t *foot)
int vder_icmp_recv(struct vde_buff *vdb)
{
struct icmp *ich;
struct iphdr *iph;
uint32_t tmp_ipaddr;
struct vde_buff *vdb_copy = malloc(vdb->len + sizeof(struct vde_buff));
ich = (struct icmp *) payload(vdb);
iph = iphead(vdb);
if (ich->icmp_type == ICMP_ECHO){
tmp_ipaddr = iph->saddr;
iph->saddr = iph->daddr;
iph->daddr = tmp_ipaddr;
ich->icmp_type = ICMP_ECHOREPLY;
ich->icmp_cksum = 0;
ich->icmp_cksum = htons(net_checksum(payload(vdb), vdb->len - sizeof(struct iphdr) - 14));
iph->check = htons(vder_ip_checksum(iph));
struct vde_buff *vdb_copy = malloc(vdb->len + sizeof(struct vde_buff));
struct icmp *ich_copy;
struct iphdr *iph_copy;
uint32_t tmp_ipaddr;

if (!vdb_copy)
return -1;
memcpy(vdb_copy, vdb, sizeof(struct vde_buff) + vdb->len);

ich_copy = (struct icmp *) payload(vdb_copy);
iph_copy = iphead(vdb_copy);
tmp_ipaddr = iph_copy->saddr;
iph_copy->saddr = iph_copy->daddr;
iph_copy->daddr = tmp_ipaddr;
ich_copy->icmp_type = ICMP_ECHOREPLY;
ich_copy->icmp_cksum = 0;
ich_copy->icmp_cksum = htons(net_checksum(payload(vdb_copy), vdb_copy->len - sizeof(struct iphdr) - 14));
iph_copy->check = htons(vder_ip_checksum(iph_copy));
vder_packet_send(vdb_copy, iph_copy->daddr, PROTO_ICMP);
}
memcpy(vdb_copy, vdb, sizeof(struct vde_buff) + vdb->len);
vder_packet_send(vdb_copy, iph->daddr, PROTO_ICMP);
return 0;
}
2 changes: 1 addition & 1 deletion src/vde_router/vder_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void vder_packet_recv(struct vder_iface *vif, int timeout)

if (vder_ip_input(packet)) {
/* If the packet is for us, process it here. */
//free(packet);
free(packet);
return;
} else {
struct iphdr *hdr = iphead(packet);
Comment thread
danielinux marked this conversation as resolved.
Expand Down
3 changes: 1 addition & 2 deletions src/vde_router/vder_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int qred_may_enqueue(struct vder_queue *q, struct vde_buff *b)
return 1;
} else if (q->policy_opt.red.max > q->size) {
red_probability = q->policy_opt.red.P *
((double)q->size - (double)q->policy_opt.red.min /
(((double)q->size - (double)q->policy_opt.red.min) /
((double)q->policy_opt.red.max - (double)q->policy_opt.red.min));
} else if (q->policy_opt.red.limit > q->size) {
red_probability = q->policy_opt.red.P;
Expand Down Expand Up @@ -199,4 +199,3 @@ void qtoken_setup(struct vder_queue *q, uint32_t bitrate, uint32_t limit)
q->may_enqueue = qtoken_may_enqueue;
pthread_mutex_unlock(&q->lock);
}

15 changes: 9 additions & 6 deletions src/vde_router/vder_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ int vder_udpsocket_sendto(struct vder_udp_socket *sock, void *data, size_t len,
uint8_t *datagram;
struct vder_route *ro;
int bufsize;
if (len <= 0) {
size_t payload_len = len;
size_t udp_len;

if (payload_len <= 0) {
errno = EINVAL;
return -1;
}
len += sizeof(struct udphdr);
udp_len = payload_len + sizeof(struct udphdr);

ro = vder_get_route(dst);
if (!ro) {
errno = EHOSTUNREACH;
return -1;
}

bufsize = sizeof(struct vde_buff) + sizeof(struct vde_ethernet_header) + sizeof(struct iphdr) + sizeof(struct udphdr) + len;
bufsize = sizeof(struct vde_buff) + sizeof(struct vde_ethernet_header) + sizeof(struct iphdr) + udp_len;
b = malloc(bufsize);
if (!b)
return -1;
Expand All @@ -109,14 +112,14 @@ int vder_udpsocket_sendto(struct vder_udp_socket *sock, void *data, size_t len,
b->priority = PRIO_BESTEFFORT;
uh = (struct udphdr *) payload(b);
datagram = (uint8_t *)((payload(b) + sizeof(struct udphdr)));
memcpy(datagram, data, len);
memcpy(datagram, data, payload_len);

uh->sport = sock->port;
uh->dport = dstport;
uh->len = htons(len);
uh->len = htons(udp_len);
uh->crc = 0;
Comment thread
danielinux marked this conversation as resolved.
vder_packet_send(b, dst, PROTO_UDP);
return len;
return payload_len;
Comment thread
danielinux marked this conversation as resolved.
}

int vder_udpsocket_sendto_broadcast(struct vder_udp_socket *sock, void *data, size_t len,
Expand Down
4 changes: 2 additions & 2 deletions src/vde_switch/plugins/iplog.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ static void ip_find_in_hash_update(int len, unsigned char *addr, unsigned char *
struct ip_hash_entry *e;
int k = ip_hash(len, addr);
time_t now;
for(e = iph[k]; e && memcmp(e->ipaddr, addr, len) && e->len == len &&
e->vlan == vlan; e = e->next)
for(e = iph[k]; e && (e->len != len || e->vlan != vlan ||
memcmp(e->ipaddr, addr, len) != 0); e = e->next)
;
if(e == NULL) {
e = (struct ip_hash_entry *) malloc(sizeof(*e)+(len-4));
Expand Down
2 changes: 1 addition & 1 deletion src/vde_switch/qtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ unsigned int qtimer_add(time_t period,int times,void (*call)(),void *arg)
n=activeqt++;
if (qtf == NULL) {
qtf=malloc(sizeof(struct qt_timer));
if (qth == NULL) {
if (qtf == NULL) {
return -1;
}
/*all the fields but qt_arg get initialized */
Expand Down
2 changes: 1 addition & 1 deletion src/vde_switch/vde_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ unsigned char add_type(struct swmodule *mgr,int prio)
printlog(LOG_ERR,"realloc fdtypes %s",strerror(errno));
exit(1);
}
memset(fdtypes+ntypes,0,sizeof(struct swmodule *) * maxtypes-ntypes);
memset(fdtypes+ntypes,0,sizeof(struct swmodule *) * (maxtypes-ntypes));
i=ntypes;
} else
for(i=0; fdtypes[i] != NULL; i++)
Expand Down
1 change: 1 addition & 0 deletions src/vde_vxlan/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void vxlan_process() {
switch (dest_addr) {
case 0:
printlog(LOG_DEBUG, "Not found");
break;
case 1:
plug_send(&pkt.pkt,len-offsetof(struct vxlan_pkt,pkt));
printlog(LOG_DEBUG, "Send to VDE");
Expand Down
7 changes: 6 additions & 1 deletion src/wirefilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ static int markov_step(int i) {
static int markovms(void) {
if (markov_numnodes > 1) {
struct timeval v;
long long now;
long long next;

gettimeofday(&v,NULL);
unsigned long long next=markov_next-(v.tv_sec*1000+v.tv_usec/1000);
now = v.tv_sec * 1000LL + v.tv_usec / 1000;
next = markov_next - now;
if (next < 0) next=0;
return next;
} else
Expand Down Expand Up @@ -1522,6 +1526,7 @@ int main(int argc,char *argv[])
usage();
}
}
break;
case MGMTMODEARG:
sscanf(optarg,"%o",&mgmtmode);
break;
Expand Down
Loading