#include <palacios/vmm_dev_mgr.h>
#include <palacios/vm_guest_mem.h>
#include <palacios/vmm_sprintf.h>
-#include <palacios/vmm_packet.h>
+#include <interfaces/vmm_packet.h>
-#ifndef CONFIG_DEBUG_NIC_BRIDGE
+#ifndef V3_CONFIG_DEBUG_NIC_BRIDGE
#undef PrintDebug
#define PrintDebug(fmt, args...)
#endif
};
static int bridge_send(uint8_t * buf, uint32_t len,
- void * private_data, struct vm_device *dev){
- //struct nic_bridge_state *bridge = (struct nic_bridge_state *)private_data;
+ int synchronize,
+ void * private_data) {
-#ifdef CONFIG_DEBUG_NIC_BRIDGE
+#ifdef V3_CONFIG_DEBUG_NIC_BRIDGE
{
PrintDebug("NIC Bridge: send pkt size: %d\n", len);
- //v3_hexdump(buf, len, NULL, 0);
+ v3_hexdump(buf, len, NULL, 0);
}
#endif
return V3_send_raw(buf, len);
}
-
-static int packet_input(struct v3_vm_info * vm,
- struct v3_packet_event * evt,
- void * private_data) {
- struct nic_bridge_state *bridge = (struct nic_bridge_state *)private_data;
-
- PrintDebug("NIC_BRIDGE: Incoming packet size: %d\n", evt->size);
+static int packet_input(struct v3_vm_info * vm,
+ struct v3_packet_event * evt,
+ void * private_data) {
+ struct nic_bridge_state * bridge = (struct nic_bridge_state *)private_data;
+
+#ifdef V3_CONFIG_DEBUG_NIC_BRIDGE
+ {
+ PrintDebug("NIC Bridge: recv pkt size: %d\n", evt->size);
+ v3_hexdump(evt->pkt, evt->size, NULL, 0);
+ }
+#endif
return bridge->net_ops.recv(evt->pkt,
- evt->size,
- bridge->net_ops.frontend_data);
+ evt->size,
+ bridge->net_ops.frontend_data);
}
-static int vnet_nic_free(struct vm_device * dev) {
- struct nic_bridge_state * bridge = dev->private_data;
+static int nic_bridge_free(struct nic_bridge_state * bridge) {
/*detach from front device */
}
static struct v3_device_ops dev_ops = {
- .free = vnet_nic_free,
- .reset = NULL,
- .start = NULL,
- .stop = NULL,
+ .free = (int (*)(void *))nic_bridge_free,
+
};
-static int vnet_nic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
+static int nic_bridge_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
struct nic_bridge_state * bridge = NULL;
char * dev_id = v3_cfg_val(cfg, "ID");
bridge = (struct nic_bridge_state *)V3_Malloc(sizeof(struct nic_bridge_state));
memset(bridge, 0, sizeof(struct nic_bridge_state));
- struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, bridge);
+ struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, bridge);
- if (v3_attach_device(vm, dev) == -1) {
+ if (dev == NULL) {
PrintError("Could not attach device %s\n", dev_id);
+ V3_Free(bridge);
return -1;
}
&(bridge->net_ops), frontend_cfg, bridge) == -1) {
PrintError("Could not connect %s to frontend %s\n",
dev_id, v3_cfg_val(frontend_cfg, "tag"));
+ v3_remove_device(dev);
return -1;
}
PrintDebug("NIC-Bridge: Connect %s to frontend %s\n",
dev_id, v3_cfg_val(frontend_cfg, "tag"));
- v3_hook_host_event(vm, HOST_PACKET_EVT, V3_HOST_EVENT_HANDLER(packet_input), dev);
+
+ 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;
}
-device_register("NIC_BRIDGE", vnet_nic_init)
+device_register("NIC_BRIDGE", nic_bridge_init)