summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e660363)
Returning a static data buffer makes code more brittle and definitely
not thread-safe, so this commit switches to using a caller-provided
buffer instead.
Signed-off-by: Ben Pfaff <blp@nicira.com>
ds_put_cstr(s, "controller(");
if (reason != OFPR_ACTION) {
ds_put_cstr(s, "controller(");
if (reason != OFPR_ACTION) {
+ char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
+
ds_put_format(s, "reason=%s,",
ds_put_format(s, "reason=%s,",
- ofputil_packet_in_reason_to_string(reason));
+ ofputil_packet_in_reason_to_string(
+ reason, reasonbuf, sizeof reasonbuf));
}
if (controller->max_len != UINT16_MAX) {
ds_put_format(s, "max_len=%"PRIu16",", controller->max_len);
}
if (controller->max_len != UINT16_MAX) {
ds_put_format(s, "max_len=%"PRIu16",", controller->max_len);
ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
int verbosity)
{
ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
int verbosity)
{
+ char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
struct ofputil_packet_in pin;
int error;
int i;
struct ofputil_packet_in pin;
int error;
int i;
}
ds_put_format(string, " (via %s)",
}
ds_put_format(string, " (via %s)",
- ofputil_packet_in_reason_to_string(pin.reason));
+ ofputil_packet_in_reason_to_string(pin.reason, reasonbuf,
+ sizeof reasonbuf));
ds_put_format(string, " data_len=%zu", pin.packet_len);
if (pin.buffer_id == UINT32_MAX) {
ds_put_format(string, " data_len=%zu", pin.packet_len);
if (pin.buffer_id == UINT32_MAX) {
ds_put_cstr(string, " PACKET_IN:");
for (j = 0; j < 32; j++) {
if (nac->packet_in_mask[i] & htonl(1u << j)) {
ds_put_cstr(string, " PACKET_IN:");
for (j = 0; j < 32; j++) {
if (nac->packet_in_mask[i] & htonl(1u << j)) {
- ds_put_format(string, " %s",
- ofputil_packet_in_reason_to_string(j));
+ char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
+ const char *reason;
+
+ reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
+ sizeof reasonbuf);
+ ds_put_format(string, " %s", reason);
}
}
if (!nac->packet_in_mask[i]) {
}
}
if (!nac->packet_in_mask[i]) {
+/* Returns a string form of 'reason'. The return value is either a statically
+ * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
+ * 'bufsize' should be at least OFPUTIL_PACKET_IN_REASON_BUFSIZE. */
-ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason reason)
+ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason reason,
+ char *reasonbuf, size_t bufsize)
- static char s[INT_STRLEN(int) + 1];
-
switch (reason) {
case OFPR_NO_MATCH:
return "no_match";
switch (reason) {
case OFPR_NO_MATCH:
return "no_match";
case OFPR_N_REASONS:
default:
case OFPR_N_REASONS:
default:
- sprintf(s, "%d", (int) reason);
- return s;
+ snprintf(reasonbuf, bufsize, "%d", (int) reason);
+ return reasonbuf;
int i;
for (i = 0; i < OFPR_N_REASONS; i++) {
int i;
for (i = 0; i < OFPR_N_REASONS; i++) {
- if (!strcasecmp(s, ofputil_packet_in_reason_to_string(i))) {
+ char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
+ const char *reason_s;
+
+ reason_s = ofputil_packet_in_reason_to_string(i, reasonbuf,
+ sizeof reasonbuf);
+ if (!strcasecmp(s, reason_s)) {
*reason = i;
return true;
}
*reason = i;
return true;
}
#include "netdev.h"
#include "openflow/nicira-ext.h"
#include "openvswitch/types.h"
#include "netdev.h"
#include "openflow/nicira-ext.h"
#include "openvswitch/types.h"
enum ofputil_protocol protocol,
enum nx_packet_in_format);
enum ofputil_protocol protocol,
enum nx_packet_in_format);
-const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason);
+enum { OFPUTIL_PACKET_IN_REASON_BUFSIZE = INT_STRLEN(int) + 1 };
+const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason,
+ char *reasonbuf,
+ size_t bufsize);
bool ofputil_packet_in_reason_from_string(const char *,
enum ofp_packet_in_reason *);
bool ofputil_packet_in_reason_from_string(const char *,
enum ofp_packet_in_reason *);