X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Fiface-packet.c;h=6ec4de0a1d9278e88cea38a9364de63d024e1b95;hb=2cb41f7db5b9f89113432d6b3daff4807ba8e5f2;hp=d55b854a565cd9d25f3b9cac0325f2bf11aea8fe;hpb=0975ec64a5a81c1c51bc49791b40e785d1679d28;p=palacios.git diff --git a/linux_module/iface-packet.c b/linux_module/iface-packet.c index d55b854..6ec4de0 100644 --- a/linux_module/iface-packet.c +++ b/linux_module/iface-packet.c @@ -99,13 +99,13 @@ init_socket(struct raw_interface * iface, const char * eth_dev){ err = sock_create(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL), &(iface->raw_sock)); if (err < 0) { - printk(KERN_WARNING "Could not create a PF_PACKET Socket, err %d\n", err); + WARNING("Could not create a PF_PACKET Socket, err %d\n", err); return -1; } net_dev = dev_get_by_name(&init_net, eth_dev); if(net_dev == NULL) { - printk(KERN_WARNING "Palacios Packet: Unable to get index for device %s\n", eth_dev); + WARNING("Palacios Packet: Unable to get index for device %s\n", eth_dev); sock_release(iface->raw_sock); return -1; } @@ -120,13 +120,13 @@ init_socket(struct raw_interface * iface, const char * eth_dev){ sizeof(sock_addr)); if (err < 0){ - printk(KERN_WARNING "Error binding raw packet to device %s, %d\n", eth_dev, err); + WARNING("Error binding raw packet to device %s, %d\n", eth_dev, err); sock_release(iface->raw_sock); return -1; } - printk(KERN_INFO "Bind a palacios raw packet interface to device %s, device index %d\n", + INFO("Bind a palacios raw packet interface to device %s, device index %d\n", eth_dev, net_dev->ifindex); return 0; @@ -158,16 +158,21 @@ static int packet_recv_thread( void * arg ) { struct v3_packet * recver_state; struct raw_interface * iface = (struct raw_interface *)arg; - pkt = (unsigned char *)kmalloc(ETHERNET_PACKET_LEN, GFP_KERNEL); + pkt = (unsigned char *)palacios_alloc(ETHERNET_PACKET_LEN); + + if (!pkt) { + ERROR("Unable to allocate packet in vnet receive thread\n"); + return -1; + } - printk("Palacios Raw Packet Bridge: Staring receiving on ethernet device %s\n", + INFO("Palacios Raw Packet Bridge: Staring receiving on ethernet device %s\n", iface->eth_dev); while (!kthread_should_stop()) { size = recv_pkt(iface->raw_sock, pkt, ETHERNET_PACKET_LEN); if (size < 0) { - printk(KERN_WARNING "Palacios raw packet receive error, Server terminated\n"); + WARNING("Palacios raw packet receive error, Server terminated\n"); break; } @@ -199,7 +204,7 @@ init_raw_interface(struct raw_interface * iface, const char * eth_dev){ memcpy(iface->eth_dev, eth_dev, V3_ETHINT_NAMELEN); if(init_socket(iface, eth_dev) !=0) { - printk("packet: fails to initiate raw socket\n"); + WARNING("packet: fails to initiate raw socket\n"); return -1; } @@ -222,7 +227,7 @@ deinit_raw_interface(struct raw_interface * iface){ palacios_free_htable(iface->mac_to_recver, 0, 0); list_for_each_entry_safe(recver_state, tmp_state, &(iface->brdcast_recvers), node) { - kfree(recver_state); + palacios_free(recver_state); } } @@ -248,24 +253,24 @@ palacios_packet_connect(struct v3_packet * packet, struct raw_interface * iface; unsigned long flags; - spin_lock_irqsave(&(packet_state.lock), flags); + palacios_spinlock_lock_irqsave(&(packet_state.lock), flags); iface = find_interface(host_nic); - spin_unlock_irqrestore(&(packet_state.lock),flags); + palacios_spinlock_unlock_irqrestore(&(packet_state.lock),flags); if(iface == NULL){ - iface = (struct raw_interface *)kmalloc(sizeof(struct raw_interface), GFP_KERNEL); + iface = (struct raw_interface *)palacios_alloc(sizeof(struct raw_interface)); if (!iface) { - printk("Palacios Packet Interface: Fails to allocate interface\n"); + ERROR("Palacios Packet Interface: Fails to allocate interface\n"); return -1; } if(init_raw_interface(iface, host_nic) != 0) { - printk("Palacios Packet Interface: Fails to initiate an raw interface on device %s\n", host_nic); - kfree(iface); + ERROR("Palacios Packet Interface: Fails to initiate an raw interface on device %s\n", host_nic); + palacios_free(iface); return -1; } - spin_lock_irqsave(&(packet_state.lock), flags); + palacios_spinlock_lock_irqsave(&(packet_state.lock), flags); list_add(&(iface->node), &(packet_state.open_interfaces)); - spin_unlock_irqrestore(&(packet_state.lock),flags); + palacios_spinlock_unlock_irqrestore(&(packet_state.lock),flags); } packet->host_packet_data = iface; @@ -275,7 +280,7 @@ palacios_packet_connect(struct v3_packet * packet, (addr_t)packet->dev_mac, (addr_t)packet); - printk(KERN_INFO "Packet: Add Receiver MAC to ethernet device %s: %2x:%2x:%2x:%2x:%2x:%2x\n", + INFO("Packet: Add Receiver MAC to ethernet device %s: %2x:%2x:%2x:%2x:%2x:%2x\n", iface->eth_dev, packet->dev_mac[0], packet->dev_mac[1], packet->dev_mac[2], packet->dev_mac[3], @@ -296,8 +301,7 @@ palacios_packet_send(struct v3_packet * packet, if(iface->inited == 0 || iface->raw_sock == NULL){ - printk("Palacios Packet Interface: Send fails due to inapproriate interface\n"); - + ERROR("Palacios Packet Interface: Send fails due to inapproriate interface\n"); return -1; } @@ -342,7 +346,7 @@ static int packet_init( void ) { V3_Init_Packet(&palacios_packet_hooks); memset(&packet_state, 0, sizeof(struct palacios_packet_state)); - spin_lock_init(&(packet_state.lock)); + palacios_spinlock_init(&(packet_state.lock)); INIT_LIST_HEAD(&(packet_state.open_interfaces)); // REGISTER GLOBAL CONTROL to add interfaces... @@ -355,8 +359,10 @@ static int packet_deinit( void ) { list_for_each_entry_safe(iface, tmp, &(packet_state.open_interfaces), node) { deinit_raw_interface(iface); - kfree(iface); + palacios_free(iface); } + + palacios_spinlock_deinit(&(packet_state.lock)); return 0; }