#include <net/genetlink.h>
#include <linux/ip.h>
#include <linux/delay.h>
+#include <linux/time.h>
#include <linux/etherdevice.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/ethtool.h>
#include <linux/random.h>
#include <asm/system.h>
+#include <asm/div64.h>
#include <linux/netfilter_bridge.h>
#include <linux/netfilter_ipv4.h>
#include <linux/inetdevice.h>
if (dp == NULL)
goto err_unlock;
+ dp->dp_idx = dp_idx;
+
/* Setup our "of" device */
err = dp_dev_setup(dp);
if (err)
goto err_free_dp;
- dp->dp_idx = dp_idx;
- dp->id = get_datapath_id(dp->netdev);
dp->chain = chain_create(dp);
if (dp->chain == NULL)
goto err_destroy_dp_dev;
static void
do_port_input(struct net_bridge_port *p, struct sk_buff *skb)
{
+ /* Make our own copy of the packet. Otherwise we will mangle the
+ * packet for anyone who came before us (e.g. tcpdump via AF_PACKET).
+ * (No one comes after us, since we tell handle_bridge() that we took
+ * the packet.) */
+ skb = skb_share_check(skb, GFP_ATOMIC);
+ if (!skb)
+ return;
+
#ifdef SUPPORT_SNAT
/* Check if this packet needs early SNAT processing. */
if (snat_pre_route(skb)) {
- kfree_skb(skb);
return;
}
#endif
/* Push the Ethernet header back on. */
skb_push(skb, ETH_HLEN);
+ skb_reset_mac_header(skb);
fwd_port_input(p->dp->chain, skb, p);
}
dp_xmit_skb(struct sk_buff *skb)
{
int len = skb->len;
- if (packet_length(skb) > skb->dev->mtu) {
+ if (packet_length(skb) > skb->dev->mtu && !skb_is_gso(skb)) {
printk("dropped over-mtu packet: %d > %d\n",
packet_length(skb), skb->dev->mtu);
kfree_skb(skb);
* forward the whole packet? */
struct sk_buff *f_skb;
struct ofp_packet_in *opi;
- struct net_bridge_port *p;
size_t fwd_len, opi_len;
int err;
}
opi->buffer_id = htonl(buffer_id);
opi->total_len = htons(skb->len);
- p = skb->dev->br_port;
- opi->in_port = htons(p ? p->port_no : OFPP_LOCAL);
+ opi->in_port = htons(skb->dev && skb->dev->br_port
+ ? skb->dev->br_port->port_no
+ : OFPP_LOCAL);
opi->reason = reason;
opi->pad = 0;
- memcpy(opi->data, skb_mac_header(skb), fwd_len);
+ skb_copy_bits(skb, 0, opi->data, fwd_len);
err = send_openflow_skb(f_skb, NULL);
out:
fill_features_reply(struct datapath *dp, struct ofp_switch_features *ofr)
{
struct net_bridge_port *p;
+ uint64_t dpid = get_datapath_id(dp->netdev);
int port_count = 0;
- ofr->datapath_id = cpu_to_be64(dp->id);
+ ofr->datapath_id = cpu_to_be64(dpid);
ofr->n_buffers = htonl(N_PKT_BUFFERS);
ofr->n_tables = dp->chain->n_tables;
return send_openflow_skb(skb, NULL);
}
+/* Convert jiffies_64 to milliseconds. */
+static u64 inline jiffies_64_to_msecs(const u64 j)
+{
+#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
+ return (MSEC_PER_SEC / HZ) * j;
+#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
+ return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
+#else
+ return (j * MSEC_PER_SEC) / HZ;
+#endif
+}
+
int
-dp_send_flow_expired(struct datapath *dp, struct sw_flow *flow,
- enum ofp_flow_expired_reason reason)
+dp_send_flow_end(struct datapath *dp, struct sw_flow *flow,
+ enum nx_flow_end_reason reason)
{
struct sk_buff *skb;
- struct ofp_flow_expired *ofe;
+ struct nx_flow_end *nfe;
- if (!(dp->flags & OFPC_SEND_FLOW_EXP))
+ if (!dp->send_flow_end)
return 0;
- ofe = alloc_openflow_skb(dp, sizeof *ofe, OFPT_FLOW_EXPIRED, 0, &skb);
- if (!ofe)
+ nfe = alloc_openflow_skb(dp, sizeof *nfe, OFPT_VENDOR, 0, &skb);
+ if (!nfe)
return -ENOMEM;
- flow_fill_match(&ofe->match, &flow->key);
+ nfe->header.vendor = htonl(NX_VENDOR_ID);
+ nfe->header.subtype = htonl(NXT_FLOW_END);
+
+ flow_fill_match(&nfe->match, &flow->key);
+
+ nfe->priority = htons(flow->priority);
+ nfe->reason = reason;
+
+ nfe->tcp_flags = flow->tcp_flags;
+ nfe->ip_tos = flow->ip_tos;
+
+ memset(nfe->pad, 0, sizeof nfe->pad);
- ofe->priority = htons(flow->priority);
- ofe->reason = reason;
- memset(ofe->pad, 0, sizeof ofe->pad);
+ nfe->init_time = cpu_to_be64(jiffies_64_to_msecs(flow->created));
+ nfe->used_time = cpu_to_be64(jiffies_64_to_msecs(flow->used));
+ nfe->end_time = cpu_to_be64(jiffies_64_to_msecs(get_jiffies_64()));
- ofe->duration = htonl((jiffies - flow->init_time) / HZ);
- memset(ofe->pad2, 0, sizeof ofe->pad2);
- ofe->packet_count = cpu_to_be64(flow->packet_count);
- ofe->byte_count = cpu_to_be64(flow->byte_count);
+ nfe->packet_count = cpu_to_be64(flow->packet_count);
+ nfe->byte_count = cpu_to_be64(flow->byte_count);
return send_openflow_skb(skb, NULL);
}
-EXPORT_SYMBOL(dp_send_flow_expired);
+EXPORT_SYMBOL(dp_send_flow_end);
int
dp_send_error_msg(struct datapath *dp, const struct sender *sender,
struct datapath *dp_get(int dp_idx)
{
- if (dp_idx < 0 || dp_idx > DP_MAX)
+ if (dp_idx < 0 || dp_idx >= DP_MAX)
return NULL;
return rcu_dereference(dps[dp_idx]);
}
if (!info->attrs[DP_GENL_A_DP_IDX])
return -EINVAL;
- dp = dp_get(nla_get_u32((info->attrs[DP_GENL_A_DP_IDX])));
+ dp = dp_get(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
if (!dp)
err = -ENOENT;
else {
genlmsg_end(ans_skb, data);
err = genlmsg_reply(ans_skb, info);
- if (!err)
- ans_skb = NULL;
+ ans_skb = NULL;
}
err:
nla_put_failure:
- if (ans_skb)
- kfree_skb(ans_skb);
+ kfree_skb(ans_skb);
rcu_read_unlock();
return err;
}
struct flow_stats_state *s = private;
struct ofp_flow_stats *ofs;
int length;
+ uint64_t duration;
length = sizeof *ofs + sf_acts->actions_len;
if (length + s->bytes_used > s->bytes_allocated)
ofs->match.pad = 0;
ofs->match.tp_src = flow->key.tp_src;
ofs->match.tp_dst = flow->key.tp_dst;
- ofs->duration = htonl((jiffies - flow->init_time) / HZ);
+
+ /* The kernel doesn't support 64-bit division, so use the 'do_div'
+ * macro instead. The first argument is replaced with the quotient,
+ * while the remainder is the return value. */
+ duration = get_jiffies_64() - flow->created;
+ do_div(duration, HZ);
+ ofs->duration = htonl(duration);
+
ofs->priority = htons(flow->priority);
ofs->idle_timeout = htons(flow->idle_timeout);
ofs->hard_timeout = htons(flow->hard_timeout);
{
struct sw_table *table = dp->chain->tables[s->table_idx];
- error = table->iterate(table, &match_key, &s->position,
- flow_stats_dump_callback, s);
+ error = table->iterate(table, &match_key, s->rq->out_port,
+ &s->position, flow_stats_dump_callback, s);
if (error)
break;
struct sw_table *table = dp->chain->tables[table_idx];
int error;
- error = table->iterate(table, &match_key, &position,
+ error = table->iterate(table, &match_key, rq->out_port, &position,
aggregate_stats_dump_callback, rpy);
if (error)
return error;
static void set_desc(void)
{
const char *uuid = dmi_get_system_info(DMI_PRODUCT_UUID);
- const char *uptr = uuid + 24;
+ const char *vendor = dmi_get_system_info(DMI_SYS_VENDOR);
+ const char *name = dmi_get_system_info(DMI_PRODUCT_NAME);
+ const char *version = dmi_get_system_info(DMI_PRODUCT_VERSION);
+ const char *serial = dmi_get_system_info(DMI_PRODUCT_SERIAL);
+ const char *uptr;
if (!uuid || *uuid == '\0' || strlen(uuid) != 36)
return;
return;
/* Only set if the UUID is from Nicira. */
+ uptr = uuid + 24;
if (strncmp(uptr, NICIRA_OUI_STR, strlen(NICIRA_OUI_STR)))
return;
- strlcpy(mfr_desc, dmi_get_system_info(DMI_SYS_VENDOR), sizeof(mfr_desc));
- snprintf(hw_desc, sizeof(hw_desc), "%s %s",
- dmi_get_system_info(DMI_PRODUCT_NAME),
- dmi_get_system_info(DMI_PRODUCT_VERSION));
- strlcpy(serial_num, dmi_get_system_info(DMI_PRODUCT_SERIAL),
- sizeof(serial_num));
+ if (vendor)
+ strlcpy(mfr_desc, vendor, sizeof(mfr_desc));
+ if (name || version)
+ snprintf(hw_desc, sizeof(hw_desc), "%s %s",
+ name ? name : "",
+ version ? version : "");
+ if (serial)
+ strlcpy(serial_num, serial, sizeof(serial_num));
}
static int __init dp_init(void)