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) {
- 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;
}
- 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) {
+ WARNING("Palacios Packet: Unable to get index for device %s\n", eth_dev);
sock_release(iface->raw_sock);
return -1;
}
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,
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",
- if_req.ifr_name, if_req.ifr_ifindex);
+ INFO("Bind a palacios raw packet interface to device %s, device index %d\n",
+ eth_dev, net_dev->ifindex);
return 0;
}
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;
}
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;
}
static void inline
deinit_raw_interface(struct raw_interface * iface){
- struct v3_packet * recver_state;
+ struct v3_packet * recver_state, * tmp_state;
kthread_stop(iface->recv_thread);
sock_release(iface->raw_sock);
palacios_free_htable(iface->mac_to_recver, 0, 0);
- list_for_each_entry(recver_state, &(iface->brdcast_recvers), node) {
- kfree(recver_state);
+ list_for_each_entry_safe(recver_state, tmp_state, &(iface->brdcast_recvers), node) {
+ palacios_free(recver_state);
}
}
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);
+ 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) {
+ 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);
- spin_unlock_irqrestore(&(packet_state.lock), flags);
-
+ ERROR("Palacios Packet Interface: Fails to initiate an raw interface on device %s\n", host_nic);
+ palacios_free(iface);
return -1;
}
-
+ palacios_spinlock_lock_irqsave(&(packet_state.lock), flags);
list_add(&(iface->node), &(packet_state.open_interfaces));
+ palacios_spinlock_unlock_irqrestore(&(packet_state.lock),flags);
}
- spin_unlock_irqrestore(&(packet_state.lock), flags);
-
packet->host_packet_data = iface;
list_add(&(packet->node), &(iface->brdcast_recvers));
(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],
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;
}
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...
}
static int packet_deinit( void ) {
- struct raw_interface * iface;
+ struct raw_interface * iface, * tmp;
- list_for_each_entry(iface, &(packet_state.open_interfaces), node) {
+ 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;
}