Skip to content

Commit ae412e7

Browse files
committed
flow: Get rid of flow_t typedef.
When userspace and the kernel were using the same structure for flows, flow_t was a useful way to indicate that a structure was really a userspace flow instead of a kernel one, but now it's better to just write "struct flow" for consistency, since OVS doesn't use typedefs for structs elsewhere. Acked-by: Jesse Gross <jesse@nicira.com>
1 parent 14608a1 commit ae412e7

19 files changed

Lines changed: 121 additions & 119 deletions

lib/classifier.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525

2626
const struct cls_field cls_fields[CLS_N_FIELDS + 1] = {
2727
#define CLS_FIELD(WILDCARDS, MEMBER, NAME) \
28-
{ offsetof(flow_t, MEMBER), \
29-
sizeof ((flow_t *)0)->MEMBER, \
28+
{ offsetof(struct flow, MEMBER), \
29+
sizeof ((struct flow *)0)->MEMBER, \
3030
WILDCARDS, \
3131
#NAME },
3232
CLS_FIELDS
3333
#undef CLS_FIELD
34-
{ sizeof(flow_t), 0, 0, "exact" },
34+
{ sizeof(struct flow), 0, 0, "exact" },
3535
};
3636

37-
static uint32_t hash_fields(const flow_t *, int table_idx);
38-
static bool equal_fields(const flow_t *, const flow_t *, int table_idx);
37+
static uint32_t hash_fields(const struct flow *, int table_idx);
38+
static bool equal_fields(const struct flow *, const struct flow *,
39+
int table_idx);
3940

4041
static int table_idx_from_wildcards(uint32_t wildcards);
4142
static struct cls_rule *table_insert(struct hmap *, struct cls_rule *);
@@ -46,7 +47,7 @@ static struct cls_bucket *find_bucket(struct hmap *, size_t hash,
4647
static struct cls_rule *search_table(const struct hmap *table, int field_idx,
4748
const struct cls_rule *);
4849
static struct cls_rule *search_exact_table(const struct classifier *,
49-
size_t hash, const flow_t *);
50+
size_t hash, const struct flow *);
5051
static bool rules_match_1wild(const struct cls_rule *fixed,
5152
const struct cls_rule *wild, int field_idx);
5253
static bool rules_match_2wild(const struct cls_rule *wild1,
@@ -55,7 +56,7 @@ static bool rules_match_2wild(const struct cls_rule *wild1,
5556
/* Converts the flow in 'flow' into a cls_rule in 'rule', with the given
5657
* 'wildcards' and 'priority'.*/
5758
void
58-
cls_rule_from_flow(const flow_t *flow, uint32_t wildcards,
59+
cls_rule_from_flow(const struct flow *flow, uint32_t wildcards,
5960
unsigned int priority, struct cls_rule *rule)
6061
{
6162
rule->flow = *flow;
@@ -280,7 +281,7 @@ classifier_remove(struct classifier *cls, struct cls_rule *rule)
280281
* rules added more recently take priority over rules added less recently, but
281282
* this is subject to change and should not be depended upon.) */
282283
struct cls_rule *
283-
classifier_lookup(const struct classifier *cls, const flow_t *flow)
284+
classifier_lookup(const struct classifier *cls, const struct flow *flow)
284285
{
285286
struct cls_rule *rule = classifier_lookup_exact(cls, flow);
286287
if (!rule) {
@@ -290,15 +291,15 @@ classifier_lookup(const struct classifier *cls, const flow_t *flow)
290291
}
291292

292293
struct cls_rule *
293-
classifier_lookup_exact(const struct classifier *cls, const flow_t *flow)
294+
classifier_lookup_exact(const struct classifier *cls, const struct flow *flow)
294295
{
295296
return (!hmap_is_empty(&cls->exact_table)
296297
? search_exact_table(cls, flow_hash(flow, 0), flow)
297298
: NULL);
298299
}
299300

300301
struct cls_rule *
301-
classifier_lookup_wild(const struct classifier *cls, const flow_t *flow)
302+
classifier_lookup_wild(const struct classifier *cls, const struct flow *flow)
302303
{
303304
struct cls_rule *best = NULL;
304305
if (cls->n_rules > hmap_count(&cls->exact_table)) {
@@ -318,7 +319,7 @@ classifier_lookup_wild(const struct classifier *cls, const flow_t *flow)
318319

319320
struct cls_rule *
320321
classifier_find_rule_exactly(const struct classifier *cls,
321-
const flow_t *target, uint32_t wildcards,
322+
const struct flow *target, uint32_t wildcards,
322323
unsigned int priority)
323324
{
324325
struct cls_bucket *bucket;
@@ -356,7 +357,7 @@ classifier_find_rule_exactly(const struct classifier *cls,
356357
* Two rules are considered overlapping if a packet could match both. */
357358
bool
358359
classifier_rule_overlaps(const struct classifier *cls,
359-
const flow_t *target, uint32_t wildcards,
360+
const struct flow *target, uint32_t wildcards,
360361
unsigned int priority)
361362
{
362363
struct cls_rule target_rule;
@@ -506,7 +507,7 @@ classifier_for_each(const struct classifier *cls, int include,
506507
}
507508

508509
static struct cls_bucket *create_bucket(struct hmap *, size_t hash,
509-
const flow_t *fixed);
510+
const struct flow *fixed);
510511
static struct cls_rule *bucket_insert(struct cls_bucket *, struct cls_rule *);
511512

512513
static inline bool equal_bytes(const void *, const void *, size_t n);
@@ -515,7 +516,7 @@ static inline bool equal_bytes(const void *, const void *, size_t n);
515516
* (CLS_F_IDX_*) are less than 'table_idx'. (If 'table_idx' is
516517
* CLS_F_IDX_EXACT, hashes all the fields in 'flow'). */
517518
static uint32_t
518-
hash_fields(const flow_t *flow, int table_idx)
519+
hash_fields(const struct flow *flow, int table_idx)
519520
{
520521
/* I just know I'm going to hell for writing code this way.
521522
*
@@ -581,7 +582,7 @@ hash_fields(const flow_t *flow, int table_idx)
581582
*
582583
* Returns true if all the compared fields are equal, false otherwise. */
583584
static bool
584-
equal_fields(const flow_t *a, const flow_t *b, int table_idx)
585+
equal_fields(const struct flow *a, const struct flow *b, int table_idx)
585586
{
586587
/* XXX The generated code could be better here. */
587588
#define CLS_FIELD(WILDCARDS, MEMBER, NAME) \
@@ -685,7 +686,7 @@ find_bucket(struct hmap *table, size_t hash, const struct cls_rule *rule)
685686
/* Creates a bucket and inserts it in 'table' with the given 'hash' and 'fixed'
686687
* values. Returns the new bucket. */
687688
static struct cls_bucket *
688-
create_bucket(struct hmap *table, size_t hash, const flow_t *fixed)
689+
create_bucket(struct hmap *table, size_t hash, const struct flow *fixed)
689690
{
690691
struct cls_bucket *bucket = xmalloc(sizeof *bucket);
691692
list_init(&bucket->rules);
@@ -746,7 +747,7 @@ read_uint32(const void *p)
746747
* The compared field is the one with wildcard bit or bits 'field_wc', offset
747748
* 'rule_ofs' within cls_rule's "fields" member, and length 'len', in bytes. */
748749
static inline bool ALWAYS_INLINE
749-
field_matches(const flow_t *a_, const flow_t *b_,
750+
field_matches(const struct flow *a_, const struct flow *b_,
750751
uint32_t wildcards, uint32_t nw_src_mask, uint32_t nw_dst_mask,
751752
uint32_t field_wc, int ofs, int len)
752753
{
@@ -787,7 +788,7 @@ rules_match(const struct cls_rule *a, const struct cls_rule *b,
787788
case CLS_F_IDX_##NAME: \
788789
if (!field_matches(&a->flow, &b->flow, \
789790
wildcards, nw_src_mask, nw_dst_mask, \
790-
WILDCARDS, offsetof(flow_t, MEMBER), \
791+
WILDCARDS, offsetof(struct flow, MEMBER), \
791792
sizeof a->flow.MEMBER)) { \
792793
return false; \
793794
} \
@@ -884,7 +885,7 @@ search_table(const struct hmap *table, int field_idx,
884885

885886
static struct cls_rule *
886887
search_exact_table(const struct classifier *cls, size_t hash,
887-
const flow_t *target)
888+
const struct flow *target)
888889
{
889890
struct cls_rule *rule;
890891

lib/classifier.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* performance (see above). To adjust the ordering, change the order of the
5757
* lines. */
5858
#define CLS_FIELDS \
59-
/* flow_t all-caps */ \
59+
/* struct flow all-caps */ \
6060
/* wildcard bit(s) member name name */ \
6161
/* ----------------- ----------- -------- */ \
6262
CLS_FIELD(OFPFW_IN_PORT, in_port, IN_PORT) \
@@ -86,7 +86,7 @@ enum {
8686

8787
/* Field information. */
8888
struct cls_field {
89-
int ofs; /* Offset in flow_t. */
89+
int ofs; /* Offset in struct flow. */
9090
int len; /* Length in bytes. */
9191
uint32_t wildcards; /* OFPFW_* bit or bits for this field. */
9292
const char *name; /* Name (for debugging). */
@@ -104,7 +104,7 @@ struct classifier {
104104
struct cls_bucket {
105105
struct hmap_node hmap_node; /* Within struct classifier 'tables'. */
106106
struct list rules; /* In order from highest to lowest priority. */
107-
flow_t fixed; /* Values for fixed fields. */
107+
struct flow fixed; /* Values for fixed fields. */
108108
};
109109

110110
/* A flow classification rule.
@@ -117,13 +117,13 @@ struct cls_rule {
117117
struct list list; /* Within struct cls_bucket 'rules'. */
118118
struct hmap_node hmap; /* Within struct classifier 'exact_table'. */
119119
} node;
120-
flow_t flow; /* All field values. */
120+
struct flow flow; /* All field values. */
121121
struct flow_wildcards wc; /* Wildcards for fields. */
122122
unsigned int priority; /* Larger numbers are higher priorities. */
123123
unsigned int table_idx; /* Index into struct classifier 'tables'. */
124124
};
125125

126-
void cls_rule_from_flow(const flow_t *, uint32_t wildcards,
126+
void cls_rule_from_flow(const struct flow *, uint32_t wildcards,
127127
unsigned int priority, struct cls_rule *);
128128
void cls_rule_from_match(const struct ofp_match *, unsigned int priority,
129129
bool tun_id_from_cookie, uint64_t cookie,
@@ -143,12 +143,13 @@ int classifier_count_exact(const struct classifier *);
143143
struct cls_rule *classifier_insert(struct classifier *, struct cls_rule *);
144144
void classifier_insert_exact(struct classifier *, struct cls_rule *);
145145
void classifier_remove(struct classifier *, struct cls_rule *);
146-
struct cls_rule *classifier_lookup(const struct classifier *, const flow_t *);
146+
struct cls_rule *classifier_lookup(const struct classifier *,
147+
const struct flow *);
147148
struct cls_rule *classifier_lookup_wild(const struct classifier *,
148-
const flow_t *);
149+
const struct flow *);
149150
struct cls_rule *classifier_lookup_exact(const struct classifier *,
150-
const flow_t *);
151-
bool classifier_rule_overlaps(const struct classifier *, const flow_t *,
151+
const struct flow *);
152+
bool classifier_rule_overlaps(const struct classifier *, const struct flow *,
152153
uint32_t wildcards, unsigned int priority);
153154

154155
typedef void cls_cb_func(struct cls_rule *, void *aux);
@@ -164,7 +165,7 @@ void classifier_for_each_match(const struct classifier *,
164165
const struct cls_rule *,
165166
int include, cls_cb_func *, void *aux);
166167
struct cls_rule *classifier_find_rule_exactly(const struct classifier *,
167-
const flow_t *target,
168+
const struct flow *target,
168169
uint32_t wildcards,
169170
unsigned int priority);
170171

lib/dhcp-client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ do_receive_msg(struct dhclient *cli, struct dhcp_msg *msg)
942942
for (; cli->received < 50; cli->received++) {
943943
const struct ip_header *ip;
944944
const struct dhcp_header *dhcp;
945-
flow_t flow;
945+
struct flow flow;
946946
int error;
947947

948948
ofpbuf_clear(&b);

lib/dpif-netdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ dpif_netdev_execute(struct dpif *dpif,
835835
struct dp_netdev *dp = get_dp_netdev(dpif);
836836
struct ofpbuf copy;
837837
bool mutates;
838-
flow_t key;
838+
struct flow key;
839839
int error;
840840

841841
if (packet->size < ETH_HEADER_LEN || packet->size > UINT16_MAX) {

lib/flow.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pull_icmp(struct ofpbuf *packet)
7878
}
7979

8080
static void
81-
parse_vlan(struct ofpbuf *b, flow_t *flow)
81+
parse_vlan(struct ofpbuf *b, struct flow *flow)
8282
{
8383
struct qtag_prefix {
8484
uint16_t eth_type; /* ETH_TYPE_VLAN */
@@ -139,7 +139,7 @@ parse_ethertype(struct ofpbuf *b)
139139
*/
140140
int
141141
flow_extract(struct ofpbuf *packet, uint32_t tun_id, uint16_t in_port,
142-
flow_t *flow)
142+
struct flow *flow)
143143
{
144144
struct ofpbuf b = *packet;
145145
struct eth_header *eth;
@@ -235,7 +235,7 @@ flow_extract(struct ofpbuf *packet, uint32_t tun_id, uint16_t in_port,
235235
* arguments must have been initialized through a call to flow_extract().
236236
*/
237237
void
238-
flow_extract_stats(const flow_t *flow, struct ofpbuf *packet,
238+
flow_extract_stats(const struct flow *flow, struct ofpbuf *packet,
239239
struct odp_flow_stats *stats)
240240
{
241241
memset(stats, '\0', sizeof(*stats));
@@ -254,8 +254,8 @@ flow_extract_stats(const flow_t *flow, struct ofpbuf *packet,
254254
/* Extract 'flow' with 'wildcards' into the OpenFlow match structure
255255
* 'match'. */
256256
void
257-
flow_to_match(const flow_t *flow, uint32_t wildcards, bool tun_id_from_cookie,
258-
struct ofp_match *match)
257+
flow_to_match(const struct flow *flow, uint32_t wildcards,
258+
bool tun_id_from_cookie, struct ofp_match *match)
259259
{
260260
if (!tun_id_from_cookie) {
261261
wildcards &= OFPFW_ALL;
@@ -281,7 +281,7 @@ flow_to_match(const flow_t *flow, uint32_t wildcards, bool tun_id_from_cookie,
281281

282282
void
283283
flow_from_match(const struct ofp_match *match, bool tun_id_from_cookie,
284-
uint64_t cookie, flow_t *flow, uint32_t *flow_wildcards)
284+
uint64_t cookie, struct flow *flow, uint32_t *flow_wildcards)
285285
{
286286
uint32_t wildcards = ntohl(match->wildcards);
287287

@@ -310,15 +310,15 @@ flow_from_match(const struct ofp_match *match, bool tun_id_from_cookie,
310310
}
311311

312312
char *
313-
flow_to_string(const flow_t *flow)
313+
flow_to_string(const struct flow *flow)
314314
{
315315
struct ds ds = DS_EMPTY_INITIALIZER;
316316
flow_format(&ds, flow);
317317
return ds_cstr(&ds);
318318
}
319319

320320
void
321-
flow_format(struct ds *ds, const flow_t *flow)
321+
flow_format(struct ds *ds, const struct flow *flow)
322322
{
323323
ds_put_format(ds, "tunnel%08"PRIx32":in_port%04"PRIx16
324324
":vlan%"PRIu16":pcp%"PRIu8
@@ -344,7 +344,7 @@ flow_format(struct ds *ds, const flow_t *flow)
344344
}
345345

346346
void
347-
flow_print(FILE *stream, const flow_t *flow)
347+
flow_print(FILE *stream, const struct flow *flow)
348348
{
349349
char *s = flow_to_string(flow);
350350
fputs(s, stream);

lib/flow.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ struct ds;
3131
struct ofp_match;
3232
struct ofpbuf;
3333

34-
typedef struct flow flow_t;
3534
struct flow {
3635
uint32_t tun_id; /* Encapsulating tunnel ID. */
3736
uint32_t nw_src; /* IP source address. */
@@ -56,39 +55,40 @@ BUILD_ASSERT_DECL(offsetof(struct flow, nw_tos) == FLOW_SIG_SIZE - 1);
5655
BUILD_ASSERT_DECL(sizeof(((struct flow *)0)->nw_tos) == 1);
5756
BUILD_ASSERT_DECL(sizeof(struct flow) == FLOW_SIG_SIZE + FLOW_PAD_SIZE);
5857

59-
int flow_extract(struct ofpbuf *, uint32_t tun_id, uint16_t in_port, flow_t *);
60-
void flow_extract_stats(const flow_t *flow, struct ofpbuf *packet,
58+
int flow_extract(struct ofpbuf *, uint32_t tun_id, uint16_t in_port,
59+
struct flow *);
60+
void flow_extract_stats(const struct flow *flow, struct ofpbuf *packet,
6161
struct odp_flow_stats *stats);
62-
void flow_to_match(const flow_t *, uint32_t wildcards, bool tun_id_cookie,
62+
void flow_to_match(const struct flow *, uint32_t wildcards, bool tun_id_cookie,
6363
struct ofp_match *);
6464
void flow_from_match(const struct ofp_match *, bool tun_id_from_cookie,
65-
uint64_t cookie, flow_t *, uint32_t *wildcards);
66-
char *flow_to_string(const flow_t *);
67-
void flow_format(struct ds *, const flow_t *);
68-
void flow_print(FILE *, const flow_t *);
69-
static inline int flow_compare(const flow_t *, const flow_t *);
70-
static inline bool flow_equal(const flow_t *, const flow_t *);
71-
static inline size_t flow_hash(const flow_t *, uint32_t basis);
65+
uint64_t cookie, struct flow *, uint32_t *wildcards);
66+
char *flow_to_string(const struct flow *);
67+
void flow_format(struct ds *, const struct flow *);
68+
void flow_print(FILE *, const struct flow *);
69+
static inline int flow_compare(const struct flow *, const struct flow *);
70+
static inline bool flow_equal(const struct flow *, const struct flow *);
71+
static inline size_t flow_hash(const struct flow *, uint32_t basis);
7272

7373
static inline int
74-
flow_compare(const flow_t *a, const flow_t *b)
74+
flow_compare(const struct flow *a, const struct flow *b)
7575
{
7676
return memcmp(a, b, FLOW_SIG_SIZE);
7777
}
7878

7979
static inline bool
80-
flow_equal(const flow_t *a, const flow_t *b)
80+
flow_equal(const struct flow *a, const struct flow *b)
8181
{
8282
return !flow_compare(a, b);
8383
}
8484

8585
static inline size_t
86-
flow_hash(const flow_t *flow, uint32_t basis)
86+
flow_hash(const struct flow *flow, uint32_t basis)
8787
{
8888
return hash_bytes(flow, FLOW_SIG_SIZE, basis);
8989
}
9090

91-
/* Information on wildcards for a flow, as a supplement to flow_t. */
91+
/* Information on wildcards for a flow, as a supplement to struct flow. */
9292
struct flow_wildcards {
9393
uint32_t wildcards; /* enum ofp_flow_wildcards (in host order). */
9494
uint32_t nw_src_mask; /* 1-bit in each significant nw_src bit. */

lib/learning-switch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ process_switch_features(struct lswitch *sw, struct rconn *rconn OVS_UNUSED,
305305
}
306306

307307
static uint16_t
308-
lswitch_choose_destination(struct lswitch *sw, const flow_t *flow)
308+
lswitch_choose_destination(struct lswitch *sw, const struct flow *flow)
309309
{
310310
uint16_t out_port;
311311

@@ -372,7 +372,7 @@ process_packet_in(struct lswitch *sw, struct rconn *rconn, void *opi_)
372372

373373
size_t pkt_ofs, pkt_len;
374374
struct ofpbuf pkt;
375-
flow_t flow;
375+
struct flow flow;
376376

377377
/* Ignore packets sent via output to OFPP_CONTROLLER. This library never
378378
* uses such an action. You never know what experiments might be going on,

0 commit comments

Comments
 (0)