X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Fiface-packet.c;h=3acb4bf61259193ee051324f9bf6853a94c4de8f;hb=80a7fd2f343c65c00d84bc64181d0e9720ae20a6;hp=c03d628a508d2734f6517aa0b2ef6e0d2b6295a9;hpb=9a32111c4074aafd55cd9590a24bd5c751a6fe61;p=palacios.git diff --git a/linux_module/iface-packet.c b/linux_module/iface-packet.c index c03d628..3acb4bf 100644 --- a/linux_module/iface-packet.c +++ b/linux_module/iface-packet.c @@ -95,7 +95,7 @@ static int init_socket(struct raw_interface * iface, const char * eth_dev){ int err; struct sockaddr_ll sock_addr; - struct ifreq if_req; + struct net_device * net_dev; err = sock_create(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL), &(iface->raw_sock)); if (err < 0) { @@ -103,14 +103,9 @@ init_socket(struct raw_interface * iface, const char * eth_dev){ return -1; } - memset(&if_req, 0, sizeof(if_req)); - strncpy(if_req.ifr_name, eth_dev, sizeof(if_req.ifr_name)); - - err = iface->raw_sock->ops->ioctl(iface->raw_sock, SIOCGIFINDEX, (long)&if_req); - if (err < 0){ - printk(KERN_WARNING "Palacios Packet: Unable to get index for device %s, error %d\n", - if_req.ifr_name, err); - + 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); sock_release(iface->raw_sock); return -1; } @@ -118,7 +113,7 @@ init_socket(struct raw_interface * iface, const char * eth_dev){ memset(&sock_addr, 0, sizeof(sock_addr)); sock_addr.sll_family = PF_PACKET; sock_addr.sll_protocol = htons(ETH_P_ALL); - sock_addr.sll_ifindex = if_req.ifr_ifindex; + sock_addr.sll_ifindex = net_dev->ifindex; err = iface->raw_sock->ops->bind(iface->raw_sock, (struct sockaddr *)&sock_addr, @@ -132,7 +127,7 @@ init_socket(struct raw_interface * iface, const char * eth_dev){ } printk(KERN_INFO "Bind a palacios raw packet interface to device %s, device index %d\n", - if_req.ifr_name, if_req.ifr_ifindex); + eth_dev, net_dev->ifindex); return 0; } @@ -257,7 +252,11 @@ palacios_packet_connect(struct v3_packet * packet, iface = find_interface(host_nic); if(iface == NULL){ - iface = (struct raw_interface *)kmalloc(sizeof(struct raw_interface), GFP_KERNEL); + iface = (struct raw_interface *)kmalloc(sizeof(struct raw_interface), GFP_ATOMIC); + if (!iface) { + printk("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);