Skip to content

Commit 95e1b63

Browse files
committed
style improvements
1 parent 670dc10 commit 95e1b63

File tree

6 files changed

+53
-54
lines changed

6 files changed

+53
-54
lines changed

codelab/fe.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ main(int argc, char **argv)
280280
main_loop(netmap_port_one, netmap_port_two, netmap_port_three, udp_port_a,
281281
udp_port_b);
282282

283-
(void) pkt_get_udp_port;
283+
(void)pkt_get_udp_port;
284284

285285
return 0;
286286
}

codelab/swap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ main(int argc, char **argv)
189189

190190
main_loop(netmap_port_one, netmap_port_two);
191191

192-
(void) pkt_udp_port_swap;
192+
(void)pkt_udp_port_swap;
193193

194194
return 0;
195195
}

solutions/fe.c

+13-14
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pkt_copy_or_drop(struct nm_desc *dst, const char *buf, unsigned len)
8888

8989
if (nm_ring_space(txring)) {
9090
struct netmap_slot *ts = &txring->slot[txring->head];
91-
char *txbuf = NETMAP_BUF(txring, ts->buf_idx);
91+
char *txbuf = NETMAP_BUF(txring, ts->buf_idx);
9292

9393
ts->len = len;
9494
memcpy(txbuf, buf, len);
@@ -112,26 +112,26 @@ route_forward(struct nm_desc *one, struct nm_desc *two, struct nm_desc *three,
112112
int nrx;
113113

114114
rxring = NETMAP_RXRING(one->nifp, si);
115-
nrx = nm_ring_space(rxring);
115+
nrx = nm_ring_space(rxring);
116116
if (nrx == 0) {
117117
si++;
118118
continue;
119119
}
120120

121-
rxhead = rxring->head;
121+
rxhead = rxring->head;
122122
for (; nrx > 0; nrx--, rxhead = nm_ring_next(rxring, rxhead)) {
123123
struct netmap_slot *rs = &rxring->slot[rxhead];
124-
char *rxbuf = NETMAP_BUF(rxring, rs->buf_idx);
125-
int udp_port = pkt_get_udp_port(rxbuf);
124+
char *rxbuf = NETMAP_BUF(rxring, rs->buf_idx);
125+
int udp_port = pkt_get_udp_port(rxbuf);
126126

127127
if (udp_port == udp_port_a) {
128128
fwda += pkt_copy_or_drop(two, rxbuf, rs->len);
129129
} else if (udp_port == udp_port_b) {
130130
fwdb += pkt_copy_or_drop(three, rxbuf, rs->len);
131131
}
132-
tot ++;
132+
tot++;
133133
}
134-
rxring->head = rxring->cur = rxhead;
134+
rxring->head = rxring->cur = rxhead;
135135
}
136136
}
137137
#endif /* SOLUTION */
@@ -233,9 +233,9 @@ main_loop(const char *netmap_port_one, const char *netmap_port_two,
233233
int ret;
234234
int two_ready, three_ready;
235235

236-
pfd[0].fd = nmd_one->fd;
237-
pfd[1].fd = nmd_two->fd;
238-
pfd[2].fd = nmd_three->fd;
236+
pfd[0].fd = nmd_one->fd;
237+
pfd[1].fd = nmd_two->fd;
238+
pfd[2].fd = nmd_three->fd;
239239
pfd[0].events = POLLIN;
240240
pfd[1].events = 0;
241241
pfd[2].events = 0;
@@ -244,7 +244,7 @@ main_loop(const char *netmap_port_one, const char *netmap_port_two,
244244
* line blocking (we don't know in advance which packets are going to
245245
* be forwarded where). As a result, unfortunately, we may end dropping
246246
* packets. */
247-
two_ready = rx_ready(nmd_two);
247+
two_ready = rx_ready(nmd_two);
248248
three_ready = rx_ready(nmd_three);
249249
if (!two_ready) {
250250
pfd[1].events |= POLLIN;
@@ -270,8 +270,7 @@ main_loop(const char *netmap_port_one, const char *netmap_port_two,
270270
}
271271

272272
/* Route and forward from port one to ports two and three. */
273-
route_forward(nmd_one, nmd_two, nmd_three, udp_port_a,
274-
udp_port_b);
273+
route_forward(nmd_one, nmd_two, nmd_three, udp_port_a, udp_port_b);
275274
#endif /* SOLUTION */
276275

277276
/* Forward traffic from ports two and three back to port one. */
@@ -385,7 +384,7 @@ main(int argc, char **argv)
385384
main_loop(netmap_port_one, netmap_port_two, netmap_port_three, udp_port_a,
386385
udp_port_b);
387386

388-
(void) pkt_get_udp_port;
387+
(void)pkt_get_udp_port;
389388

390389
return 0;
391390
}

solutions/forward.c

+17-16
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ pkt_select(const char *buf, int udp_port)
8282

8383
#ifdef SOLUTION
8484
static void
85-
forward_pkts(struct nm_desc *src, struct nm_desc *dst, int udp_port, int zerocopy)
85+
forward_pkts(struct nm_desc *src, struct nm_desc *dst, int udp_port,
86+
int zerocopy)
8687
{
8788
unsigned int si = src->first_rx_ring;
8889
unsigned int di = dst->first_tx_ring;
@@ -95,8 +96,8 @@ forward_pkts(struct nm_desc *src, struct nm_desc *dst, int udp_port, int zerocop
9596

9697
rxring = NETMAP_RXRING(src->nifp, si);
9798
txring = NETMAP_TXRING(dst->nifp, di);
98-
nrx = nm_ring_space(rxring);
99-
ntx = nm_ring_space(txring);
99+
nrx = nm_ring_space(rxring);
100+
ntx = nm_ring_space(txring);
100101
if (nrx == 0) {
101102
si++;
102103
continue;
@@ -106,13 +107,13 @@ forward_pkts(struct nm_desc *src, struct nm_desc *dst, int udp_port, int zerocop
106107
continue;
107108
}
108109

109-
rxhead = rxring->head;
110-
txhead = txring->head;
111-
for (; nrx > 0 && ntx > 0;
112-
nrx --, rxhead = nm_ring_next(rxring, rxhead), tot ++) {
110+
rxhead = rxring->head;
111+
txhead = txring->head;
112+
for (; nrx > 0 && ntx > 0;
113+
nrx--, rxhead = nm_ring_next(rxring, rxhead), tot++) {
113114
struct netmap_slot *rs = &rxring->slot[rxhead];
114115
struct netmap_slot *ts = &txring->slot[txhead];
115-
char *rxbuf = NETMAP_BUF(rxring, rs->buf_idx);
116+
char *rxbuf = NETMAP_BUF(rxring, rs->buf_idx);
116117

117118
if (!pkt_select(rxbuf, udp_port)) {
118119
continue; /* discard */
@@ -121,8 +122,8 @@ forward_pkts(struct nm_desc *src, struct nm_desc *dst, int udp_port, int zerocop
121122
ts->len = rs->len;
122123
if (zerocopy) {
123124
uint32_t idx = ts->buf_idx;
124-
ts->buf_idx = rs->buf_idx;
125-
rs->buf_idx = idx;
125+
ts->buf_idx = rs->buf_idx;
126+
rs->buf_idx = idx;
126127
/* report the buffer change. */
127128
ts->flags |= NS_BUF_CHANGED;
128129
rs->flags |= NS_BUF_CHANGED;
@@ -131,12 +132,12 @@ forward_pkts(struct nm_desc *src, struct nm_desc *dst, int udp_port, int zerocop
131132
memcpy(txbuf, rxbuf, ts->len);
132133
}
133134
txhead = nm_ring_next(txring, txhead);
134-
ntx --;
135-
fwd ++;
135+
ntx--;
136+
fwd++;
136137
}
137138
/* Update state of netmap ring. */
138-
rxring->head = rxring->cur = rxhead;
139-
txring->head = txring->cur = txhead;
139+
rxring->head = rxring->cur = rxhead;
140+
txring->head = txring->cur = txhead;
140141
}
141142
}
142143
#endif /* SOLUTION */
@@ -182,8 +183,8 @@ main_loop(const char *netmap_port_one, const char *netmap_port_two,
182183
struct pollfd pfd[2];
183184
int ret;
184185

185-
pfd[0].fd = nmd_one->fd;
186-
pfd[1].fd = nmd_two->fd;
186+
pfd[0].fd = nmd_one->fd;
187+
pfd[1].fd = nmd_two->fd;
187188
pfd[0].events = 0;
188189
pfd[1].events = 0;
189190
if (!rx_ready(nmd_one)) {

solutions/sink.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ main_loop(const char *netmap_port, int udp_port)
6969
if (!errno) {
7070
printf("Failed to nm_open(%s): not a netmap port\n", netmap_port);
7171
} else {
72-
printf("Failed to nm_open(%s): %s\n", netmap_port,
73-
strerror(errno));
72+
printf("Failed to nm_open(%s): %s\n", netmap_port, strerror(errno));
7473
}
7574
return -1;
7675
}
@@ -82,7 +81,7 @@ main_loop(const char *netmap_port, int udp_port)
8281
unsigned int ri;
8382
int ret;
8483

85-
pfd[0].fd = nmd->fd;
84+
pfd[0].fd = nmd->fd;
8685
pfd[0].events = POLLIN;
8786

8887
/* We poll with a timeout to have a chance to break the main loop if
@@ -96,25 +95,25 @@ main_loop(const char *netmap_port, int udp_port)
9695
}
9796

9897
/* Scan all the receive rings. */
99-
for (ri = nmd->first_rx_ring; ri <= nmd->last_rx_ring; ri ++) {
98+
for (ri = nmd->first_rx_ring; ri <= nmd->last_rx_ring; ri++) {
10099
struct netmap_ring *rxring;
101100
unsigned head, tail;
102101
int batch;
103102

104103
rxring = NETMAP_RXRING(nmd->nifp, ri);
105-
head = rxring->head;
106-
tail = rxring->tail;
107-
batch = tail - head;
104+
head = rxring->head;
105+
tail = rxring->tail;
106+
batch = tail - head;
108107
if (batch < 0) {
109108
batch += rxring->num_slots;
110109
}
111110
tot += batch;
112111
for (; head != tail; head = nm_ring_next(rxring, head)) {
113112
struct netmap_slot *slot = rxring->slot + head;
114-
char *buf = NETMAP_BUF(rxring, slot->buf_idx);
113+
char *buf = NETMAP_BUF(rxring, slot->buf_idx);
115114

116115
if (udp_port_match(buf, slot->len, udp_port)) {
117-
cnt ++;
116+
cnt++;
118117
}
119118
}
120119
rxring->cur = rxring->head = head;

solutions/swap.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ swap_and_forward(struct nm_desc *src, struct nm_desc *dst, int zerocopy)
9292

9393
rxring = NETMAP_RXRING(src->nifp, si);
9494
txring = NETMAP_TXRING(dst->nifp, di);
95-
nrx = nm_ring_space(rxring);
96-
ntx = nm_ring_space(txring);
95+
nrx = nm_ring_space(rxring);
96+
ntx = nm_ring_space(txring);
9797
if (nrx == 0) {
9898
si++;
9999
continue;
@@ -103,25 +103,25 @@ swap_and_forward(struct nm_desc *src, struct nm_desc *dst, int zerocopy)
103103
continue;
104104
}
105105

106-
rxhead = rxring->head;
107-
txhead = txring->head;
108-
for (; nrx > 0 && ntx > 0; nrx--, ntx--, tot++) {
106+
rxhead = rxring->head;
107+
txhead = txring->head;
108+
for (; nrx > 0 && ntx > 0; nrx--, ntx--, tot++) {
109109
struct netmap_slot *rs = &rxring->slot[rxhead];
110110
struct netmap_slot *ts = &txring->slot[txhead];
111111
char *txbuf;
112112

113113
ts->len = rs->len;
114114
if (zerocopy) {
115115
uint32_t idx = ts->buf_idx;
116-
ts->buf_idx = rs->buf_idx;
117-
rs->buf_idx = idx;
116+
ts->buf_idx = rs->buf_idx;
117+
rs->buf_idx = idx;
118118
/* report the buffer change. */
119119
ts->flags |= NS_BUF_CHANGED;
120120
rs->flags |= NS_BUF_CHANGED;
121121
txbuf = NETMAP_BUF(txring, ts->buf_idx);
122122
} else {
123123
char *rxbuf = NETMAP_BUF(rxring, rs->buf_idx);
124-
txbuf = NETMAP_BUF(txring, ts->buf_idx);
124+
txbuf = NETMAP_BUF(txring, ts->buf_idx);
125125
memcpy(txbuf, rxbuf, ts->len);
126126
}
127127

@@ -130,8 +130,8 @@ swap_and_forward(struct nm_desc *src, struct nm_desc *dst, int zerocopy)
130130
rxhead = nm_ring_next(rxring, rxhead);
131131
}
132132
/* Update state of netmap ring. */
133-
rxring->head = rxring->cur = rxhead;
134-
txring->head = txring->cur = txhead;
133+
rxring->head = rxring->cur = rxhead;
134+
txring->head = txring->cur = txhead;
135135
}
136136
}
137137
#endif /* SOLUTION */
@@ -176,8 +176,8 @@ main_loop(const char *netmap_port_one, const char *netmap_port_two)
176176
struct pollfd pfd[2];
177177
int ret;
178178

179-
pfd[0].fd = nmd_one->fd;
180-
pfd[1].fd = nmd_two->fd;
179+
pfd[0].fd = nmd_one->fd;
180+
pfd[1].fd = nmd_two->fd;
181181
pfd[0].events = 0;
182182
pfd[1].events = 0;
183183
if (!rx_ready(nmd_one)) {
@@ -289,7 +289,7 @@ main(int argc, char **argv)
289289

290290
main_loop(netmap_port_one, netmap_port_two);
291291

292-
(void) pkt_udp_port_swap;
292+
(void)pkt_udp_port_swap;
293293

294294
return 0;
295295
}

0 commit comments

Comments
 (0)