From 061bfea46df4048440a219472719e5def71f4090 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 26 Dec 2012 14:56:01 -0800 Subject: [PATCH] ofproto: Use NULL "desc" values to indicate defaults. This saves a small amount of memory. It should also save a small amount of time for reconfiguration starting with an upcoming commit where it becomes possible to change the dp_desc away from the default (because it will not be necessary to compare the current value against the default). Signed-off-by: Ben Pfaff --- ofproto/ofproto-provider.h | 10 +++++----- ofproto/ofproto.c | 32 ++++++++++++++++++++++---------- ofproto/ofproto.h | 6 ------ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index bc0105fc1..f2274ef13 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -52,11 +52,11 @@ struct ofproto { * ofproto-dpif implementation */ bool forward_bpdu; /* Option to allow forwarding of BPDU frames * when NORMAL action is invoked. */ - char *mfr_desc; /* Manufacturer. */ - char *hw_desc; /* Hardware. */ - char *sw_desc; /* Software version. */ - char *serial_desc; /* Serial number. */ - char *dp_desc; /* Datapath description. */ + char *mfr_desc; /* Manufacturer (NULL for default)b. */ + char *hw_desc; /* Hardware (NULL for default). */ + char *sw_desc; /* Software version (NULL for default). */ + char *serial_desc; /* Serial number (NULL for default). */ + char *dp_desc; /* Datapath description (NULL for default). */ enum ofp_config_flags frag_handling; /* One of OFPC_*. */ /* Datapath. */ diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 00b727407..939ad2020 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -407,11 +407,11 @@ ofproto_create(const char *datapath_name, const char *datapath_type, OFPROTO_FLOW_EVICTION_THRESHOLD_DEFAULT); ofproto->forward_bpdu = false; ofproto->fallback_dpid = pick_fallback_dpid(); - ofproto->mfr_desc = xstrdup(DEFAULT_MFR_DESC); - ofproto->hw_desc = xstrdup(DEFAULT_HW_DESC); - ofproto->sw_desc = xstrdup(DEFAULT_SW_DESC); - ofproto->serial_desc = xstrdup(DEFAULT_SERIAL_DESC); - ofproto->dp_desc = xstrdup(DEFAULT_DP_DESC); + ofproto->mfr_desc = NULL; + ofproto->hw_desc = NULL; + ofproto->sw_desc = NULL; + ofproto->serial_desc = NULL; + ofproto->dp_desc = NULL; ofproto->frag_handling = OFPC_FRAG_NORMAL; hmap_init(&ofproto->ports); shash_init(&ofproto->port_by_name); @@ -2393,17 +2393,29 @@ static enum ofperr handle_desc_stats_request(struct ofconn *ofconn, const struct ofp_header *request) { + static const char *default_mfr_desc = "Nicira, Inc."; + static const char *default_hw_desc = "Open vSwitch"; + static const char *default_sw_desc = VERSION; + static const char *default_serial_desc = "None"; + static const char *default_dp_desc = "None"; + struct ofproto *p = ofconn_get_ofproto(ofconn); struct ofp_desc_stats *ods; struct ofpbuf *msg; msg = ofpraw_alloc_stats_reply(request, 0); ods = ofpbuf_put_zeros(msg, sizeof *ods); - ovs_strlcpy(ods->mfr_desc, p->mfr_desc, sizeof ods->mfr_desc); - ovs_strlcpy(ods->hw_desc, p->hw_desc, sizeof ods->hw_desc); - ovs_strlcpy(ods->sw_desc, p->sw_desc, sizeof ods->sw_desc); - ovs_strlcpy(ods->serial_num, p->serial_desc, sizeof ods->serial_num); - ovs_strlcpy(ods->dp_desc, p->dp_desc, sizeof ods->dp_desc); + ovs_strlcpy(ods->mfr_desc, p->mfr_desc ? p->mfr_desc : default_mfr_desc, + sizeof ods->mfr_desc); + ovs_strlcpy(ods->hw_desc, p->hw_desc ? p->hw_desc : default_hw_desc, + sizeof ods->hw_desc); + ovs_strlcpy(ods->sw_desc, p->sw_desc ? p->sw_desc : default_sw_desc, + sizeof ods->sw_desc); + ovs_strlcpy(ods->serial_num, + p->serial_desc ? p->serial_desc : default_serial_desc, + sizeof ods->serial_num); + ovs_strlcpy(ods->dp_desc, p->dp_desc ? p->dp_desc : default_dp_desc, + sizeof ods->dp_desc); ofconn_send_reply(ofconn, msg); return 0; diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h index 27a55e97c..cedb2cdf0 100644 --- a/ofproto/ofproto.h +++ b/ofproto/ofproto.h @@ -132,12 +132,6 @@ struct ofproto_controller { uint8_t dscp; /* DSCP value for controller connection. */ }; -#define DEFAULT_MFR_DESC "Nicira, Inc." -#define DEFAULT_HW_DESC "Open vSwitch" -#define DEFAULT_SW_DESC VERSION -#define DEFAULT_SERIAL_DESC "None" -#define DEFAULT_DP_DESC "None" - void ofproto_enumerate_types(struct sset *types); const char *ofproto_normalize_type(const char *); -- 2.43.0