From 1be5ff7596ab018eb0491176af493d8c51cf1cc8 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 26 May 2011 16:41:52 -0700 Subject: [PATCH] connmgr: New function ofconn_send_error(). An upcoming commit will sometimes make connmgr responsible for sending error replies, so it's reasonable for it to have a function to do that. --- ofproto/connmgr.c | 13 +++++++++++++ ofproto/connmgr.h | 2 ++ ofproto/ofproto.c | 13 +------------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 403a1403d..bdebd3bf1 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -778,6 +778,19 @@ ofconn_send_replies(const struct ofconn *ofconn, struct list *replies) } } +/* Sends 'error', which should be an OpenFlow error created with + * e.g. ofp_mkerr(), on 'ofconn', as a reply to 'request'. Only at most the + * first 64 bytes of 'request' are used. */ +void +ofconn_send_error(const struct ofconn *ofconn, + const struct ofp_header *request, int error) +{ + struct ofpbuf *msg = ofputil_encode_error_msg(error, request); + if (msg) { + ofconn_send_reply(ofconn, msg); + } +} + /* Same as pktbuf_retrieve(), using the pktbuf owned by 'ofconn'. */ int ofconn_pktbuf_retrieve(struct ofconn *ofconn, uint32_t id, diff --git a/ofproto/connmgr.h b/ofproto/connmgr.h index 9b2e9c56b..4ac564cc1 100644 --- a/ofproto/connmgr.h +++ b/ofproto/connmgr.h @@ -88,6 +88,8 @@ void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len); void ofconn_send_reply(const struct ofconn *, struct ofpbuf *); void ofconn_send_replies(const struct ofconn *, struct list *); +void ofconn_send_error(const struct ofconn *, const struct ofp_header *request, + int error); int ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id, struct ofpbuf **bufferp, uint16_t *in_port); diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index de212ee4e..f259905c4 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1359,17 +1359,6 @@ rule_is_hidden(const struct rule *rule) return rule->cr.priority > UINT16_MAX; } -static void -send_error_oh(const struct ofconn *ofconn, const struct ofp_header *oh, - int error) -{ - struct ofpbuf *buf = ofputil_encode_error_msg(error, oh); - if (buf) { - COVERAGE_INC(ofproto_error); - ofconn_send_reply(ofconn, buf); - } -} - static int handle_echo_request(struct ofconn *ofconn, const struct ofp_header *oh) { @@ -2513,7 +2502,7 @@ handle_openflow(struct ofconn *ofconn, struct ofpbuf *ofp_msg) { int error = handle_openflow__(ofconn, ofp_msg); if (error) { - send_error_oh(ofconn, ofp_msg->data, error); + ofconn_send_error(ofconn, ofp_msg->data, error); } COVERAGE_INC(ofproto_recv_openflow); } -- 2.20.1