From: Lei Xia Date: Sun, 6 Feb 2011 17:01:55 +0000 (-0600) Subject: Change the direct network bridge interface X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=6f054c76f8e98f2e38f1f8a1f57ed7c24dc5c70e Change the direct network bridge interface --- diff --git a/palacios/include/palacios/vmm_packet.h b/palacios/include/palacios/vmm_packet.h index 8fd7822..a4ba3e5 100644 --- a/palacios/include/palacios/vmm_packet.h +++ b/palacios/include/palacios/vmm_packet.h @@ -27,14 +27,16 @@ #ifdef __V3VEE__ int V3_send_raw(const char * pkt, uint32_t len); -int V3_packet_register_mac(const char * mac, struct v3_vm_info * vm); +int V3_packet_add_recver(const char * mac, struct v3_vm_info * vm); +int V3_packet_del_recver(const char * mac, struct v3_vm_info * vm); #endif struct v3_packet_hooks { int (*send)(const char * pkt, unsigned int size, void * private_data); - int (*register_mac)(const char * mac, struct v3_vm_info * vm); + int (*add_recver)(const char * mac, struct v3_vm_info * vm); + int (*del_recver)(const char * mac, struct v3_vm_info * vm); }; extern void V3_Init_Packet(struct v3_packet_hooks * hooks); diff --git a/palacios/src/devices/nic_bridge.c b/palacios/src/devices/nic_bridge.c index 009633a..ed1cd92 100644 --- a/palacios/src/devices/nic_bridge.c +++ b/palacios/src/devices/nic_bridge.c @@ -112,7 +112,7 @@ static int nic_bridge_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { dev_id, v3_cfg_val(frontend_cfg, "tag")); - V3_packet_register_mac(bridge->net_ops.fnt_mac, vm); + V3_packet_add_recver(bridge->net_ops.fnt_mac, vm); v3_hook_host_event(vm, HOST_PACKET_EVT, V3_HOST_EVENT_HANDLER(packet_input), bridge); return 0; diff --git a/palacios/src/palacios/vmm_packet.c b/palacios/src/palacios/vmm_packet.c index 643fd1b..bda3b1f 100644 --- a/palacios/src/palacios/vmm_packet.c +++ b/palacios/src/palacios/vmm_packet.c @@ -32,9 +32,15 @@ int V3_send_raw(const char * pkt, uint32_t len) { } -int V3_register_mac(const char * mac, struct v3_vm_info * vm){ +int V3_packet_add_recver(const char * mac, struct v3_vm_info * vm){ - return packet_hooks->register_mac(mac, vm); + return packet_hooks->add_recver(mac, vm); +} + + +int V3_packet_del_recver(const char * mac, struct v3_vm_info * vm){ + + return packet_hooks->del_recver(mac, vm); } void V3_Init_Packet(struct v3_packet_hooks * hooks) { diff --git a/palacios/src/palacios/vmm_vnet_core.c b/palacios/src/palacios/vmm_vnet_core.c index 18720b1..99b61c7 100644 --- a/palacios/src/palacios/vmm_vnet_core.c +++ b/palacios/src/palacios/vmm_vnet_core.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifndef CONFIG_DEBUG_VNET #undef PrintDebug @@ -31,15 +32,15 @@ #endif struct eth_hdr { - uint8_t dst_mac[6]; - uint8_t src_mac[6]; + uint8_t dst_mac[ETH_ALEN]; + uint8_t src_mac[ETH_ALEN]; uint16_t type; /* indicates layer 3 protocol type */ } __attribute__((packed)); struct vnet_dev { int dev_id; - uint8_t mac_addr[6]; + uint8_t mac_addr[ETH_ALEN]; struct v3_vm_info * vm; struct v3_vnet_dev_ops dev_ops; void * private_data; @@ -99,7 +100,7 @@ static struct { #ifdef CONFIG_DEBUG_VNET -static inline void mac_to_string(char mac[6], char * buf) { +static inline void mac_to_string(char * mac, char * buf) { snprintf(buf, 100, "%d:%d:%d:%d:%d:%d", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -163,7 +164,7 @@ static int add_route_to_cache(const struct v3_vnet_pkt * pkt, struct route_list memcpy(routes->hash_buf, pkt->hash_buf, VNET_HASH_SIZE); if (v3_htable_insert(vnet_state.route_cache, (addr_t)routes->hash_buf, (addr_t)routes) == 0) { - PrintError("Vnet: Failed to insert new route entry to the cache\n"); + PrintError("VNET/P Core: Failed to insert new route entry to the cache\n"); return -1; } @@ -171,7 +172,6 @@ static int add_route_to_cache(const struct v3_vnet_pkt * pkt, struct route_list } static int clear_hash_cache() { - v3_free_htable(vnet_state.route_cache, 1, 1); vnet_state.route_cache = v3_create_htable(0, &hash_fn, &hash_eq); @@ -179,14 +179,13 @@ static int clear_hash_cache() { } static int look_into_cache(const struct v3_vnet_pkt * pkt, struct route_list ** routes) { - *routes = (struct route_list *)v3_htable_search(vnet_state.route_cache, (addr_t)(pkt->hash_buf)); return 0; } -static struct vnet_dev * find_dev_by_id(int idx) { +static struct vnet_dev * dev_by_id(int idx) { struct vnet_dev * dev = NULL; list_for_each_entry(dev, &(vnet_state.devs), node) { @@ -199,20 +198,19 @@ static struct vnet_dev * find_dev_by_id(int idx) { return NULL; } -static struct vnet_dev * find_dev_by_mac(char mac[6]) { +static struct vnet_dev * dev_by_mac(uint8_t * mac) { struct vnet_dev * dev = NULL; list_for_each_entry(dev, &(vnet_state.devs), node) { - if (!memcmp(dev->mac_addr, mac, 6)) + if (!memcmp(dev->mac_addr, mac, ETH_ALEN)) return dev; } return NULL; } -int v3_vnet_id_by_mac(char mac[6]){ - - struct vnet_dev *dev = find_dev_by_mac(mac); +int v3_vnet_id_by_mac(char * mac){ + struct vnet_dev *dev = dev_by_mac(mac); if (dev == NULL) return -1; @@ -228,24 +226,38 @@ int v3_vnet_add_route(struct v3_vnet_route route) { new_route = (struct vnet_route_info *)V3_Malloc(sizeof(struct vnet_route_info)); memset(new_route, 0, sizeof(struct vnet_route_info)); - PrintDebug("Vnet: vnet_add_route_entry: dst_id: %d, dst_type: %d\n", + PrintDebug("VNET/P Core: add_route_entry: dst_id: %d, dst_type: %d\n", route.dst_id, route.dst_type); - memcpy(new_route->route_def.src_mac, route.src_mac, 6); - memcpy(new_route->route_def.dst_mac, route.dst_mac, 6); + memcpy(new_route->route_def.src_mac, route.src_mac, ETH_ALEN); + memcpy(new_route->route_def.dst_mac, route.dst_mac, ETH_ALEN); new_route->route_def.src_mac_qual = route.src_mac_qual; new_route->route_def.dst_mac_qual = route.dst_mac_qual; - new_route->route_def.dst_id = route.dst_id; new_route->route_def.dst_type = route.dst_type; - new_route->route_def.src_id = route.src_id; new_route->route_def.src_type = route.src_type; - - if (new_route->route_def.dst_type == LINK_INTERFACE) { - new_route->dst_dev = find_dev_by_id(new_route->route_def.dst_id); + + if(route.dst_id == -1){ + if (new_route->route_def.dst_type == LINK_INTERFACE) { + new_route->dst_dev = dev_by_mac(route.dst_mac); + } + new_route->route_def.dst_id = new_route->dst_dev->dev_id; + } else { + new_route->route_def.dst_id = route.dst_id; + if (new_route->route_def.dst_type == LINK_INTERFACE) { + new_route->dst_dev = dev_by_id(new_route->route_def.dst_id); + } } - if (new_route->route_def.src_type == LINK_INTERFACE) { - new_route->src_dev = find_dev_by_id(new_route->route_def.src_id); + if(route.src_id == -1){ + if (new_route->route_def.src_type == LINK_INTERFACE) { + new_route->src_dev = dev_by_mac(route.src_mac); + } + new_route->route_def.src_id = new_route->src_dev->dev_id; + } else { + new_route->route_def.src_id = route.src_id; + if (new_route->route_def.src_type == LINK_INTERFACE) { + new_route->src_dev = dev_by_id(new_route->route_def.src_id); + } } flags = v3_lock_irqsave(vnet_state.lock); @@ -265,7 +277,7 @@ int v3_vnet_add_route(struct v3_vnet_route route) { /* delete all route entries with specfied src or dst device id */ -static void inline del_routes(int dev_id){ +static void inline del_routes_by_dev(int dev_id){ struct vnet_route_info * route = NULL; unsigned long flags; @@ -306,7 +318,7 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { mac_to_string(hdr->src_mac, src_str); mac_to_string(hdr->dst_mac, dst_str); - PrintDebug("Vnet: match_route. pkt: SRC(%s), DEST(%s)\n", src_str, dst_str); + PrintDebug("VNET/P Core: match_route. pkt: SRC(%s), DEST(%s)\n", src_str, dst_str); } #endif @@ -392,7 +404,7 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { } } - PrintDebug("Vnet: match_route: Matches=%d\n", num_matches); + PrintDebug("VNET/P Core: match_route: Matches=%d\n", num_matches); if (num_matches == 0) { return NULL; @@ -422,7 +434,7 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { #ifdef CONFIG_DEBUG_VNET { int cpu = V3_Get_CPU(); - PrintDebug("VNET-core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n", + PrintDebug("VNET/P Core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n", cpu, pkt->size, pkt->src_id, pkt->src_type, pkt->dst_id, pkt->dst_type); //v3_hexdump(pkt->data, pkt->size, NULL, 0); @@ -432,16 +444,15 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { flags = v3_lock_irqsave(vnet_state.lock); look_into_cache(pkt, &matched_routes); - if (matched_routes == NULL) { - PrintDebug("Vnet: send pkt Looking into routing table\n"); + PrintDebug("VNET/P Core: send pkt Looking into routing table\n"); matched_routes = match_route(pkt); if (matched_routes) { add_route_to_cache(pkt, matched_routes); } else { - PrintDebug("Could not find route for packet... discards packet\n"); + PrintDebug("VNET/P Core: Could not find route for packet... discards packet\n"); v3_unlock_irqrestore(vnet_state.lock, flags); return 0; /* do we return -1 here?*/ } @@ -449,7 +460,7 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { v3_unlock_irqrestore(vnet_state.lock, flags); - PrintDebug("Vnet: send pkt route matches %d\n", matched_routes->num_routes); + PrintDebug("VNET/P Core: send pkt route matches %d\n", matched_routes->num_routes); for (i = 0; i < matched_routes->num_routes; i++) { struct vnet_route_info * route = matched_routes->routes[i]; @@ -460,33 +471,33 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { pkt->dst_id = route->route_def.dst_id; if (bridge == NULL || (bridge->active == 0)) { - PrintDebug("VNET: No active bridge to sent data to\n"); - continue; + PrintDebug("VNET/P Core: No active bridge to sent data to\n"); + continue; } if(bridge->brg_ops.input(bridge->vm, pkt, bridge->private_data) < 0){ - PrintDebug("VNET: Packet not sent properly to bridge\n"); + PrintDebug("VNET/P Core: Packet not sent properly to bridge\n"); continue; } } else if (route->route_def.dst_type == LINK_INTERFACE) { if (route->dst_dev == NULL || route->dst_dev->active == 0){ - PrintDebug("VNET: No active device to sent data to\n"); + PrintDebug("VNET/P Core: No active device to sent data to\n"); continue; } if(route->dst_dev->dev_ops.input(route->dst_dev->vm, pkt, route->dst_dev->private_data) < 0) { - PrintDebug("VNET: Packet not sent properly\n"); + PrintDebug("VNET/P Core: Packet not sent properly\n"); continue; } } else { - PrintError("VNET: Wrong dst type\n"); + PrintError("VNET/P Core: Wrong dst type\n"); } } return 0; } -int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t mac[6], +int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, struct v3_vnet_dev_ops *ops, void * priv_data){ struct vnet_dev * new_dev = NULL; @@ -495,7 +506,7 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t mac[6], new_dev = (struct vnet_dev *)V3_Malloc(sizeof(struct vnet_dev)); if (new_dev == NULL) { - PrintError("VNET: Malloc fails\n"); + PrintError("Malloc fails\n"); return -1; } @@ -510,7 +521,7 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t mac[6], flags = v3_lock_irqsave(vnet_state.lock); - if (!find_dev_by_mac(mac)) { + if (dev_by_mac(mac) == NULL) { list_add(&(new_dev->node), &(vnet_state.devs)); new_dev->dev_id = ++vnet_state.num_devs; } @@ -519,11 +530,11 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t mac[6], /* if the device was found previosly the id should still be 0 */ if (new_dev->dev_id == 0) { - PrintError("Device Already exists\n"); + PrintError("VNET/P Core: Device Already exists\n"); return -1; } - PrintDebug("Vnet: Add Device: dev_id %d\n", new_dev->dev_id); + PrintDebug("VNET/P Core: Add Device: dev_id %d\n", new_dev->dev_id); return new_dev->dev_id; } @@ -536,17 +547,17 @@ int v3_vnet_del_dev(int dev_id){ flags = v3_lock_irqsave(vnet_state.lock); - dev = find_dev_by_id(dev_id); + dev = dev_by_id(dev_id); if (dev != NULL){ list_del(&(dev->node)); - del_routes(dev_id); + del_routes_by_dev(dev_id); } v3_unlock_irqrestore(vnet_state.lock, flags); V3_Free(dev); - PrintDebug("Vnet: Remove Device: dev_id %d\n", dev_id); + PrintDebug("VNET/P Core: Remove Device: dev_id %d\n", dev_id); return 0; } @@ -612,7 +623,7 @@ int v3_vnet_add_bridge(struct v3_vm_info * vm, v3_unlock_irqrestore(vnet_state.lock, flags); if (bridge_free == 0) { - PrintError("Bridge already set\n"); + PrintError("VNET/P Core: Bridge already set\n"); return -1; } @@ -650,21 +661,18 @@ int v3_init_vnet() { vnet_state.num_devs = 0; vnet_state.num_routes = 0; - PrintDebug("VNET: Links and Routes tables initiated\n"); - if (v3_lock_init(&(vnet_state.lock)) == -1){ - PrintError("VNET: Failure to init lock for routes table\n"); + PrintError("VNET/P Core: Fails to initiate lock\n"); } - PrintDebug("VNET: Locks initiated\n"); vnet_state.route_cache = v3_create_htable(0, &hash_fn, &hash_eq); if (vnet_state.route_cache == NULL) { - PrintError("Vnet: Route Cache Init Fails\n"); + PrintError("VNET/P Core: Fails to initiate route cache\n"); return -1; } - PrintDebug("VNET: initiated\n"); + PrintDebug("VNET/P Core is initiated\n"); return 0; }