Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel' of palacios@newskysaw.cs.northwestern.edu:/home/palacios/palacio...
[palacios.git] / linux_module / palacios-packet.c
index 2df4879..667f548 100644 (file)
 #include <linux/errno.h>
 #include <asm/msr.h>
  
-#include <palacios/vmm_packet.h>
+#include <interfaces/vmm_packet.h>
 #include <palacios/vmm_host_events.h>
-#include <palacios/vmm_vnet.h>
-#include <palacios/vmm_ethernet.h>
+#include <vnet/vnet.h>
 
-#include "palacios.h"
-#include "palacios-packet.h"
-#include "palacios-hashtable.h"
 
+#define __V3VEE__
+#include <palacios/vmm_hashtable.h>
+#include <palacios/vmm_ethernet.h>
+#undef __V3VEE__
 
+#include "palacios.h"
+#include "linux-exts.h"
 struct palacios_packet_state {
-       struct socket * raw_sock;
-       uint8_t inited;
+    struct socket * raw_sock;
+    uint8_t inited;
        
-       struct hashtable * mac_vm_cache;
-       struct task_struct * server_thread;
+    struct hashtable * mac_vm_cache;
+    struct task_struct * server_thread;
 };
 
 static struct palacios_packet_state packet_state;
@@ -38,7 +40,7 @@ static struct palacios_packet_state packet_state;
 static inline uint_t hash_fn(addr_t hdr_ptr) {    
     uint8_t * hdr_buf = (uint8_t *)hdr_ptr;
 
-    return palacios_hash_buffer(hdr_buf, ETH_ALEN);
+    return v3_hash_buffer(hdr_buf, ETH_ALEN);
 }
 
 static inline int hash_eq(addr_t key1, addr_t key2) {  
@@ -53,7 +55,7 @@ static int palacios_packet_add_recver(const char * mac,
     key = (char *)kmalloc(ETH_ALEN, GFP_KERNEL);                                       
     memcpy(key, mac, ETH_ALEN);    
 
-    if (palacios_htable_insert(packet_state.mac_vm_cache, (addr_t)key, (addr_t)vm) == 0) {
+    if (v3_htable_insert(packet_state.mac_vm_cache, (addr_t)key, (addr_t)vm) == 0) {
        printk("Palacios Packet: Failed to insert new mac entry to the hash table\n");
        return -1;
     }
@@ -64,35 +66,38 @@ static int palacios_packet_add_recver(const char * mac,
 }
 
 static int palacios_packet_del_recver(const char * mac,
-                                        struct v3_vm_info * vm){
+                                     struct v3_vm_info * vm){
 
     return 0;
 }
 
-static int init_raw_socket (const char * eth_dev){
+static int init_raw_socket(const char * eth_dev){
     int err;
     struct sockaddr_ll sock_addr;
     struct ifreq if_req;
     int dev_idx;
 
     err = sock_create(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL), &(packet_state.raw_sock)); 
+
     if (err < 0) {
        printk(KERN_WARNING "Could not create a PF_PACKET Socket, err %d\n", err);
        return -1;
     }
 
-    if(eth_dev == NULL){
+    if (eth_dev == NULL){
        eth_dev = "eth0"; /* default "eth0" */
     }
 
     memset(&if_req, 0, sizeof(if_req));
     strncpy(if_req.ifr_name, eth_dev, IFNAMSIZ);  //sizeof(if_req.ifr_name));
+
     err = packet_state.raw_sock->ops->ioctl(packet_state.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);
+
+    if (err < 0){
+       printk(KERN_WARNING "Palacios Packet: Unable to get index for device %s, error %d\n", 
+              if_req.ifr_name, err);
        dev_idx = 2; /* match ALL  2:"eth0" */
-    }
-    else{
+    } else {
        dev_idx = if_req.ifr_ifindex;
     }
 
@@ -103,7 +108,10 @@ static int init_raw_socket (const char * eth_dev){
     sock_addr.sll_protocol = htons(ETH_P_ALL);
     sock_addr.sll_ifindex = dev_idx;
 
-    err = packet_state.raw_sock->ops->bind(packet_state.raw_sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr));
+    err = packet_state.raw_sock->ops->bind(packet_state.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);
        return -1;
@@ -138,14 +146,6 @@ palacios_packet_send(const char * pkt, unsigned int len, void * private_data) {
     size = sock_sendmsg(packet_state.raw_sock, &msg, len);
     set_fs(oldfs);
 
-#if 1
-    {
-       printk("Palacios Packet: send pkt to NIC (size: %d)\n", 
-                       len);
-       print_hex_dump(NULL, "pkt_header: ", 0, 20, 20, pkt, 20, 0);
-       printk("palacios_packet_send return: %d\n", size);
-    }
-#endif
 
     return size;
 }
@@ -190,7 +190,7 @@ recv_pkt(char * pkt, int len) {
 }
 
 
-void
+static void
 send_raw_packet_to_palacios(char * pkt,
                               int len,
                               struct v3_vm_info * vm) {
@@ -214,18 +214,12 @@ static int packet_server(void * arg) {
 
     while (!kthread_should_stop()) {
        size = recv_pkt(pkt, ETHERNET_PACKET_LEN);
+
        if (size < 0) {
            printk(KERN_WARNING "Palacios raw packet receive error, Server terminated\n");
            break;
        }
 
-#if 1
-    {
-       printk("Palacios Packet: receive pkt from NIC (size: %d)\n", 
-                       size);
-       print_hex_dump(NULL, "pkt_header: ", 0, 10, 10, pkt, 20, 0);
-    }
-#endif
 
        /* if VNET is enabled, send to VNET */
        // ...
@@ -235,8 +229,9 @@ static int packet_server(void * arg) {
        // ...
 
 
-       vm = (struct v3_vm_info *)palacios_htable_search(packet_state.mac_vm_cache, (addr_t)pkt);
-       if(vm != NULL){
+       vm = (struct v3_vm_info *)v3_htable_search(packet_state.mac_vm_cache, (addr_t)pkt);
+
+       if (vm != NULL){
            printk("Find destinated VM 0x%p\n", vm);
            send_raw_packet_to_palacios(pkt, size, vm);
        }
@@ -246,31 +241,51 @@ static int packet_server(void * arg) {
 }
 
 
-int palacios_init_packet(const char * eth_dev) {
+static int packet_init( void ) {
+
+    const char * eth_dev = NULL;
 
-    if(packet_state.inited == 0){
+    if (packet_state.inited == 0){
        packet_state.inited = 1;
 
-       if(init_raw_socket(eth_dev) == -1){
+       if (init_raw_socket(eth_dev) == -1){
            printk("Error to initiate palacios packet interface\n");
            return -1;
        }
        
        V3_Init_Packet(&palacios_packet_hooks);
 
-       packet_state.mac_vm_cache = palacios_create_htable(0, &hash_fn, &hash_eq);
+       packet_state.mac_vm_cache = v3_create_htable(0, &hash_fn, &hash_eq);
 
        packet_state.server_thread = kthread_run(packet_server, NULL, "raw-packet-server");
     }
        
+
+    // REGISTER GLOBAL CONTROL to add interfaces...
+
     return 0;
 }
 
-void palacios_deinit_packet(const char * eth_dev) {
+static int packet_deinit( void ) {
+
 
     kthread_stop(packet_state.server_thread);
     packet_state.raw_sock->ops->release(packet_state.raw_sock);
-    palacios_free_htable(packet_state.mac_vm_cache, 0, 1);
+    v3_free_htable(packet_state.mac_vm_cache, 0, 1);
     packet_state.inited = 0;
+
+    return 0;
 }
 
+
+
+static struct linux_ext pkt_ext = {
+    .name = "PACKET_INTERFACE",
+    .init = packet_init,
+    .deinit = packet_deinit,
+    .guest_init = NULL,
+    .guest_deinit = NULL
+};
+
+
+register_extension(&pkt_ext);