int
dp_send_error_msg(struct datapath *dp, const struct sender *sender,
- uint16_t type, uint16_t code, const uint8_t *data, size_t len)
+ uint16_t type, uint16_t code, const void *data, size_t len)
{
struct sk_buff *skb;
struct ofp_error_msg *oem;
* struct genl_ops. This kluge supports earlier versions also. */
cb->done = dp_genl_openflow_done;
+ sender.pid = NETLINK_CB(cb->skb).pid;
+ sender.seq = cb->nlh->nlmsg_seq;
if (!cb->args[0]) {
struct nlattr *attrs[DP_GENL_A_MAX + 1];
struct ofp_stats_request *rq;
return -EINVAL;
rq = nla_data(va);
- type = ntohs(rq->type);
- if (rq->header.version != OFP_VERSION
- || rq->header.type != OFPT_STATS_REQUEST
- || ntohs(rq->header.length) != len
- || type >= ARRAY_SIZE(stats)
- || !stats[type].dump)
+ sender.xid = type = ntohs(rq->type);
+ if (rq->header.version != OFP_VERSION) {
+ dp_send_error_msg(dp, &sender, OFPET_BAD_REQUEST,
+ OFPBRC_BAD_VERSION, rq, len);
+ return -EINVAL;
+ }
+ if (rq->header.type != OFPT_STATS_REQUEST
+ || ntohs(rq->header.length) != len)
+ return -EINVAL;
+
+ if (type >= ARRAY_SIZE(stats) || !stats[type].dump) {
+ dp_send_error_msg(dp, &sender, OFPET_BAD_REQUEST,
+ OFPBRC_BAD_STAT, rq, len);
return -EINVAL;
+ }
s = &stats[type];
body_len = len - offsetof(struct ofp_stats_request, body);
cb->args[4] = (long) state;
}
} else if (cb->args[0] == 1) {
+ sender.xid = cb->args[3];
dp_idx = cb->args[1];
s = &stats[cb->args[2]];
return 0;
}
- sender.xid = cb->args[3];
- sender.pid = NETLINK_CB(cb->skb).pid;
- sender.seq = cb->nlh->nlmsg_seq;
-
osr = put_openflow_headers(dp, skb, OFPT_STATS_REPLY, &sender,
&max_openflow_len);
if (IS_ERR(osr))
int dp_send_flow_expired(struct datapath *, struct sw_flow *,
enum ofp_flow_expired_reason);
int dp_send_error_msg(struct datapath *, const struct sender *,
- uint16_t, uint16_t, const uint8_t *, size_t);
+ uint16_t, uint16_t, const void *, size_t);
int dp_update_port_flags(struct datapath *dp, const struct ofp_port_mod *opm);
int dp_send_echo_reply(struct datapath *, const struct sender *,
const struct ofp_header *);
},
};
- const struct openflow_packet *pkt;
struct ofp_header *oh;
oh = (struct ofp_header *) msg;
- if (oh->version != OFP_VERSION || oh->type >= ARRAY_SIZE(packets)
- || ntohs(oh->length) > length)
+ if (oh->version != OFP_VERSION) {
+ dp_send_error_msg(chain->dp, sender, OFPET_BAD_REQUEST,
+ OFPBRC_BAD_VERSION, msg, length);
+ return -EINVAL;
+ }
+ if (ntohs(oh->length) > length)
return -EINVAL;
- pkt = &packets[oh->type];
- if (!pkt->handler)
- return -ENOSYS;
- if (length < pkt->min_size)
- return -EFAULT;
-
- return pkt->handler(chain, sender, msg);
+ if (oh->type < ARRAY_SIZE(packets)) {
+ const struct openflow_packet *pkt = &packets[oh->type];
+ if (pkt->handler) {
+ if (length < pkt->min_size)
+ return -EFAULT;
+ return pkt->handler(chain, sender, msg);
+ }
+ }
+ dp_send_error_msg(chain->dp, sender, OFPET_BAD_REQUEST,
+ OFPBRC_BAD_TYPE, msg, length);
+ return -EINVAL;
}
/* Packet buffering. */
};
OFP_ASSERT(sizeof(struct ofp_flow_expired) == 72);
+enum ofp_error_type {
+ OFPET_BAD_REQUEST /* Request was not understood. */
+};
+
+enum ofp_bad_request_code {
+ OFPBRC_BAD_VERSION, /* ofp_header.version not supported. */
+ OFPBRC_BAD_TYPE, /* ofp_header.type not supported. */
+ OFPBRC_BAD_STAT, /* ofp_stats_request.type not supported. */
+ OFPBRC_BAD_VENDOR /* Vendor not supported (in ofp_vendor or
+ * ofp_stats_request or ofp_stats_reply). */
+};
+
/* Error message (datapath -> controller). */
struct ofp_error_msg {
struct ofp_header header;
void
dp_send_error_msg(struct datapath *dp, const struct sender *sender,
- uint16_t type, uint16_t code, const uint8_t *data, size_t len)
+ uint16_t type, uint16_t code, const void *data, size_t len)
{
struct buffer *buffer;
struct ofp_error_msg *oem;
type = ntohs(rq->type);
if (type >= ARRAY_SIZE(stats) || !stats[type].dump) {
+ dp_send_error_msg(dp, sender, OFPET_BAD_REQUEST, OFPBRC_BAD_STAT,
+ rq, rq_len);
VLOG_WARN_RL(&rl, "received stats request of unknown type %d", type);
return -EINVAL;
}
},
};
- const struct openflow_packet *pkt;
struct ofp_header *oh;
oh = (struct ofp_header *) msg;
assert(oh->version == OFP_VERSION);
- if (oh->type >= ARRAY_SIZE(packets) || ntohs(oh->length) > length)
+ if (ntohs(oh->length) > length)
return -EINVAL;
- pkt = &packets[oh->type];
- if (!pkt->handler)
- return -ENOSYS;
- if (length < pkt->min_size)
- return -EFAULT;
-
- return pkt->handler(dp, sender, msg);
+ if (oh->type < ARRAY_SIZE(packets)) {
+ const struct openflow_packet *pkt = &packets[oh->type];
+ if (pkt->handler) {
+ if (length < pkt->min_size)
+ return -EFAULT;
+ return pkt->handler(dp, sender, msg);
+ }
+ }
+ dp_send_error_msg(dp, sender, OFPET_BAD_REQUEST, OFPBRC_BAD_TYPE,
+ msg, length);
+ return -EINVAL;
}
\f
/* Packet buffering. */