Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157557314
D57076.id178044.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D57076.id178044.diff
View Options
diff --git a/libexec/tftpd/tftp-io.c b/libexec/tftpd/tftp-io.c
--- a/libexec/tftpd/tftp-io.c
+++ b/libexec/tftpd/tftp-io.c
@@ -69,17 +69,12 @@
{ -1, NULL }
};
-#define DROPPACKET(s) \
+#define DROPPACKET(...) \
if (packetdroppercentage != 0 && \
- arc4random()%100 < packetdroppercentage) { \
- tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \
- return; \
- }
-#define DROPPACKETn(s,n) \
- if (packetdroppercentage != 0 && \
- arc4random()%100 < packetdroppercentage) { \
- tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \
- return (n); \
+ arc4random() % 100 < packetdroppercentage) { \
+ tftp_log(LOG_DEBUG, "Artificial packet drop in %s", \
+ __func__); \
+ return __VA_ARGS__; \
}
const char *
@@ -104,7 +99,7 @@
int t = 1;
for (i = 0; i < 12 ; i++) {
- DROPPACKETn("send_packet", 0);
+ DROPPACKET(0);
if (sendto(peer, pkt, size, 0, (struct sockaddr *)&peer_sock,
peer_sock.ss_len) == size) {
@@ -179,12 +174,12 @@
size_t len;
int n, size;
- if (debug & DEBUG_PACKETS)
+ if (debug & DEBUG_PACKETS) {
tftp_log(LOG_DEBUG, "Sending WRQ: filename: '%s', mode '%s'",
- filename, mode
- );
+ filename, mode);
+ }
- DROPPACKETn("send_wrq", 0);
+ DROPPACKET(0);
tp = (struct tftphdr *)buf;
tp->th_opcode = htons((u_short)WRQ);
@@ -209,7 +204,7 @@
n = sendto(peer, buf, size, 0,
(struct sockaddr *)&peer_sock, peer_sock.ss_len);
if (n != size) {
- tftp_log(LOG_ERR, "send_wrq: %s", strerror(errno));
+ tftp_log(LOG_ERR, "%s: %m", __func__);
return (1);
}
return (0);
@@ -230,12 +225,12 @@
size_t len;
int n, size;
- if (debug & DEBUG_PACKETS)
+ if (debug & DEBUG_PACKETS) {
tftp_log(LOG_DEBUG, "Sending RRQ: filename: '%s', mode '%s'",
- filename, mode
- );
+ filename, mode);
+ }
- DROPPACKETn("send_rrq", 0);
+ DROPPACKET(0);
tp = (struct tftphdr *)buf;
tp->th_opcode = htons((u_short)RRQ);
@@ -262,7 +257,7 @@
n = sendto(peer, buf, size, 0,
(struct sockaddr *)&peer_sock, peer_sock.ss_len);
if (n != size) {
- tftp_log(LOG_ERR, "send_rrq: %d %s", n, strerror(errno));
+ tftp_log(LOG_ERR, "%s: %m", __func__);
return (1);
}
return (0);
@@ -285,7 +280,7 @@
if (debug & DEBUG_PACKETS)
tftp_log(LOG_DEBUG, "Sending OACK");
- DROPPACKETn("send_oack", 0);
+ DROPPACKET(0);
/*
* Send back an options acknowledgement (only the ones with
@@ -299,8 +294,8 @@
if (options[i].o_reply != NULL) {
n = snprintf(bp, size, "%s%c%s", options[i].o_type,
0, options[i].o_reply);
- bp += n+1;
- size -= n+1;
+ bp += n + 1;
+ size -= n + 1;
if (size < 0) {
tftp_log(LOG_ERR, "oack: buffer overflow");
exit(1);
@@ -331,7 +326,7 @@
if (debug & DEBUG_PACKETS)
tftp_log(LOG_DEBUG, "Sending ACK for block %d", block);
- DROPPACKETn("send_ack", 0);
+ DROPPACKET(0);
tp = (struct tftphdr *)buf;
tp->th_opcode = htons((u_short)ACK);
@@ -361,7 +356,7 @@
tftp_log(LOG_DEBUG, "Sending DATA packet %d of %d bytes",
block, size);
- DROPPACKETn("send_data", 0);
+ DROPPACKET(0);
pkt = (struct tftphdr *)buf;
@@ -408,7 +403,7 @@
fromlen = sizeof(*pfrom);
n = recvfrom(peer, data, size, 0, (struct sockaddr *)pfrom, &fromlen);
- DROPPACKETn("receive_packet", RP_TIMEOUT);
+ DROPPACKET(RP_TIMEOUT);
if (n < 0) {
/* No idea what could have happened if it isn't a timeout */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, May 23, 7:31 PM (5 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33328972
Default Alt Text
D57076.id178044.diff (3 KB)
Attached To
Mode
D57076: tftpd: Simplify packet drop macro
Attached
Detach File
Event Timeline
Log In to Comment