/*
- Palacios VNET Control Module
- (c) Lei Xia, 2010
+ * Palacios VNET Control Module
+ * (c) Lei Xia 2010
*/
+
#include <linux/spinlock.h>
#include <linux/seq_file.h>
#include <linux/proc_fs.h>
#include <vnet/vnet.h>
#include <vnet/vnet_hashtable.h>
#include "palacios-vnet.h"
+#include "palacios.h"
#define VNET_SERVER_PORT 9000
static int parse_mac_str(char * str, uint8_t * qual, uint8_t * mac) {
char * token;
- printk("Parsing MAC (%s)\n", str);
+ INFO("Parsing MAC (%s)\n", str);
*qual = MAC_NOSET;
if(strnicmp("any", str, strlen(str)) == 0){
if (strnicmp("not", token, strlen("not")) == 0) {
*qual = MAC_NOT;
} else {
- printk("Invalid MAC String token (%s)\n", token);
+ WARNING("Invalid MAC String token (%s)\n", token);
return -1;
}
}
for (i = 0; i < 6; i++) {
token = strsep(&str, ":");
if (!token) {
- printk("Invalid MAC String token (%s)\n", token);
+ WARNING("Invalid MAC String token (%s)\n", token);
return -1;
}
mac[i] = simple_strtol(token, &token, 16);
}
- printk("MAC: %2x:%2x:%2x:%2x:%2x:%2x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ DEBUG("MAC: %2x:%2x:%2x:%2x:%2x:%2x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}else {
- printk("Invalid MAC String token (%s)\n", token);
+ WARNING("Invalid MAC String token (%s)\n", token);
return -1;
}
for (i = 0; i < ETH_ALEN; i++) {
hex = strsep(&str, ":");
if (!hex) {
- printk("Invalid MAC String token (%s)\n", str);
+ WARNING("Invalid MAC String token (%s)\n", str);
return -1;
}
mac[i] = simple_strtol(hex, &hex, 16);
if (!token) {
return -1;
}
- printk("dst type =(%s)\n", token);
+ INFO("dst type =(%s)\n", token);
if (strnicmp("interface", token, strlen("interface")) == 0) {
route->dst_type = LINK_INTERFACE;
} else if (strnicmp("edge", token, strlen("edge")) == 0) {
route->dst_type = LINK_EDGE;
} else {
- printk("Invalid Destination Link Type (%s)\n", token);
+ WARNING("Invalid Destination Link Type (%s)\n", token);
return -1;
}
if (!token) {
return -1;
}
- printk("dst ID=(%s)\n", token);
+ DEBUG("dst ID=(%s)\n", token);
// Figure out link here
if (route->dst_type == LINK_EDGE) {
// Figure out Link Here
if (in4_pton(token, strlen(token), (uint8_t *)&(link_ip), '\0', NULL) != 1) {
- printk("Invalid Dst IP address (%s)\n", token);
+ WARNING("Invalid Dst IP address (%s)\n", token);
return -EFAULT;
}
if (link != NULL){
route->dst_id = link->idx;
}else{
- printk("can not find dst link %s\n", token);
+ WARNING("can not find dst link %s\n", token);
return -1;
}
- printk("link_ip = %d, link_id = %d\n", link_ip, link->idx);
+ INFO("link_ip = %d, link_id = %d\n", link_ip, link->idx);
} else if (route->dst_type == LINK_INTERFACE) {
uint8_t mac[ETH_ALEN];
if(str2mac(token, mac) == -1){
- printk("wrong MAC format (%s)\n", token);
+ WARNING("wrong MAC format (%s)\n", token);
return -1;
}
route->dst_id = v3_vnet_find_dev(mac);
if (route->dst_id == -1){
- printk("can not find dst device %s\n", token);
+ WARNING("can not find dst device %s\n", token);
return -1;
}
} else {
- printk("Unsupported dst link type\n");
+ WARNING("Unsupported dst link type\n");
return -1;
}
// src LINK
token = strsep(&str, " ");
- printk("SRC type = %s\n", token);
+ INFO("SRC type = %s\n", token);
if (!token) {
return -1;
} else if (strnicmp("any", token, strlen("any")) == 0) {
route->src_type = LINK_ANY;
} else {
- printk("Invalid Src link type (%s)\n", token);
+ WARNING("Invalid Src link type (%s)\n", token);
return -1;
}
// Figure out Link Here
if (in4_pton(token, strlen(token), (uint8_t *)&(src_ip), '\0', NULL) != 1) {
- printk("Invalid SRC IP address (%s)\n", token);
+ WARNING("Invalid SRC IP address (%s)\n", token);
return -EFAULT;
}
if (link != NULL){
route->src_id = link->idx;
}else{
- printk("can not find src link %s\n", token);
+ WARNING("can not find src link %s\n", token);
return -1;
}
} else if(route->src_type == LINK_INTERFACE){
uint8_t mac[ETH_ALEN];
if(str2mac(token, mac) == -1){
- printk("wrong MAC format (%s)\n", token);
+ WARNING("wrong MAC format (%s)\n", token);
return -1;
}
route->src_id = v3_vnet_find_dev(mac);
if (route->src_id == -1){
- printk("can not find dst device %s\n", token);
+ WARNING("can not find dst device %s\n", token);
return -1;
}
} else {
- printk("Invalid link type\n");
+ WARNING("Invalid link type\n");
return -1;
}
vnet_ctrl_s.num_routes ++;
spin_unlock_irqrestore(&(vnet_ctrl_s.lock), flags);
- printk("VNET Control: One route added to VNET core\n");
+ INFO("VNET Control: One route added to VNET core\n");
return 0;
}
vnet_ctrl_s.num_routes --;
spin_unlock_irqrestore(&(vnet_ctrl_s.lock), flags);
- printk("VNET Control: Route %d deleted from VNET\n", route->idx);
+ INFO("VNET Control: Route %d deleted from VNET\n", route->idx);
kfree(route);
route = NULL;
}
route_buf[size] = '\0';
- printk("Route written: %s\n", route_buf);
+ INFO("Route written: %s\n", route_buf);
while ((buf_iter = strsep(&line_str, "\r\n"))) {
idx_str = strsep(&buf_iter, " ");
if (!idx_str) {
- printk("Missing route idx in DEL Route command\n");
+ WARNING("Missing route idx in DEL Route command\n");
return -EFAULT;
}
d_idx = simple_strtoul(idx_str, &idx_str, 10);
- printk("VNET: deleting route %d\n", d_idx);
+ INFO("VNET: deleting route %d\n", d_idx);
list_for_each_entry(route, &(vnet_ctrl_s.route_list), node) {
if (route->idx == d_idx) {
}
}
} else {
- printk("Invalid Route command string\n");
+ WARNING("Invalid Route command string\n");
}
}
static void deinit_links_list(void){
- struct vnet_link_iter * link;
+ struct vnet_link_iter * link, * tmp_link;
- list_for_each_entry(link, &(vnet_ctrl_s.link_iter_list), node) {
+ list_for_each_entry_safe(link, tmp_link, &(vnet_ctrl_s.link_iter_list), node) {
delete_link(link);
}
}
static void deinit_routes_list(void){
- struct vnet_route_iter * route;
+ struct vnet_route_iter * route, * tmp_route;
- list_for_each_entry(route, &(vnet_ctrl_s.route_list), node) {
+ list_for_each_entry_safe(route, tmp_route, &(vnet_ctrl_s.route_list), node) {
delete_route(route);
}
}
}
while ((link_iter = strsep(&line_str, "\r\n"))) {
- printk("Link written: %s\n", link_buf);
+ DEBUG("Link written: %s\n", link_buf);
token = strsep(&link_iter, " ");
ip_str = strsep(&link_iter, " ");
if ((!ip_str) || (!link_iter)) {
- printk("Missing fields in ADD Link command\n");
+ WARNING("Missing fields in ADD Link command\n");
return -EFAULT;
}
if (in4_pton(ip_str, strlen(ip_str), (uint8_t *)&(d_ip), '\0', NULL) != 1) {
- printk("Invalid Dst IP address (%s)\n", ip_str);
+ WARNING("Invalid Dst IP address (%s)\n", ip_str);
return -EFAULT;
}
link_idx = vnet_brg_add_link(d_ip, d_port, d_proto);
if(link_idx < 0){
- printk("VNET Control: Failed to create link\n");
+ WARNING("VNET Control: Failed to create link\n");
return -EFAULT;
}
idx_str = strsep(&link_iter, " ");
if (!idx_str) {
- printk("Missing link idx in DEL Link command\n");
+ WARNING("Missing link idx in DEL Link command\n");
return -EFAULT;
}
vnet_brg_delete_link(d_idx);
- printk("VNET Control: One link deleted\n");
+ DEBUG("VNET Control: One link deleted\n");
} else {
- printk("Invalid Link command string\n");
+ WARNING("Invalid Link command string\n");
}
}
in_iter = strsep(&line_str, "\r\n");
level = simple_strtol(in_iter, &in_iter, 10);
- printk("VNET Control: Set VNET Debug level to %d\n", level);
+ DEBUG("VNET Control: Set VNET Debug level to %d\n", level);
if(level >= 0){
net_debug = level;
init_proc_files();
- printk("VNET Linux control module initiated\n");
+ NOTICE("VNET Linux control module initiated\n");
return 0;
}