tftp-utils.h revision 296373
1171095Ssam/* 2171095Ssam * Copyright (C) 2008 Edwin Groothuis. All rights reserved. 3171095Ssam * 4171095Ssam * Redistribution and use in source and binary forms, with or without 5171095Ssam * modification, are permitted provided that the following conditions 6171095Ssam * are met: 7171095Ssam * 1. Redistributions of source code must retain the above copyright 8171095Ssam * notice, this list of conditions and the following disclaimer. 9171095Ssam * 2. Redistributions in binary form must reproduce the above copyright 10171095Ssam * notice, this list of conditions and the following disclaimer in the 11171095Ssam * documentation and/or other materials provided with the distribution. 12171095Ssam * 13171095Ssam * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14171095Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15171095Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16171095Ssam * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 17171095Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18171095Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19171095Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20171095Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21171095Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22171095Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23171095Ssam * SUCH DAMAGE. 24171095Ssam */ 25171095Ssam 26171095Ssam#include <sys/cdefs.h> 27171095Ssam__FBSDID("$FreeBSD: releng/10.3/libexec/tftpd/tftp-utils.h 246139 2013-01-31 00:02:36Z marius $"); 28171095Ssam 29171095Ssam/* 30171095Ssam */ 31171095Ssam#define TIMEOUT 5 32171095Ssam#define MAX_TIMEOUTS 5 33171095Ssam 34171095Ssam/* Generic values */ 35171095Ssam#define MAXSEGSIZE 65464 /* Maximum size of the data segment */ 36173139Srwatson#define MAXPKTSIZE (MAXSEGSIZE + 4) /* Maximum size of the packet */ 37173139Srwatson 38171095Ssam/* For the blksize option */ 39171095Ssam#define BLKSIZE_MIN 8 /* Minimum size of the data segment */ 40171095Ssam#define BLKSIZE_MAX MAXSEGSIZE /* Maximum size of the data segment */ 41171095Ssam 42171095Ssam/* For the timeout option */ 43171095Ssam#define TIMEOUT_MIN 0 /* Minimum timeout value */ 44171095Ssam#define TIMEOUT_MAX 255 /* Maximum timeout value */ 45171095Ssam#define MIN_TIMEOUTS 3 46171095Ssam 47171095Ssamextern int timeoutpacket; 48171095Ssamextern int timeoutnetwork; 49171095Ssamextern int maxtimeouts; 50171095Ssamint settimeouts(int timeoutpacket, int timeoutnetwork, int maxtimeouts); 51171095Ssam 52171095Ssamextern uint16_t segsize; 53171095Ssamextern uint16_t pktsize; 54171095Ssam 55171095Ssamextern int acting_as_client; 56171095Ssam 57171095Ssam/* 58171095Ssam */ 59171095Ssamvoid unmappedaddr(struct sockaddr_in6 *sin6); 60171095Ssamssize_t get_field(int peer, char *buffer, ssize_t size); 61171095Ssam 62171095Ssam/* 63171095Ssam * Packet types 64173139Srwatson */ 65171095Ssamstruct packettypes { 66173139Srwatson int value; 67173139Srwatson const char *const name; 68173139Srwatson}; 69173139Srwatsonextern struct packettypes packettypes[]; 70173139Srwatsonconst char *packettype(int); 71173139Srwatson 72173139Srwatson/* 73171095Ssam * RP_ 74171095Ssam */ 75171095Ssamstruct rp_errors { 76171095Ssam int error; 77171095Ssam const char *const desc; 78}; 79extern struct rp_errors rp_errors[]; 80char *rp_strerror(int error); 81 82/* 83 * Debug features 84 */ 85#define DEBUG_NONE 0x0000 86#define DEBUG_PACKETS 0x0001 87#define DEBUG_SIMPLE 0x0002 88#define DEBUG_OPTIONS 0x0004 89#define DEBUG_ACCESS 0x0008 90struct debugs { 91 int value; 92 const char *const name; 93 const char *const desc; 94}; 95extern int debug; 96extern struct debugs debugs[]; 97extern int packetdroppercentage; 98int debug_find(char *s); 99int debug_finds(char *s); 100const char *debug_show(int d); 101 102/* 103 * Log routines 104 */ 105#define DEBUG(s) tftp_log(LOG_DEBUG, "%s", s) 106extern int tftp_logtostdout; 107void tftp_openlog(const char *ident, int logopt, int facility); 108void tftp_closelog(void); 109void tftp_log(int priority, const char *message, ...) __printflike(2, 3); 110 111/* 112 * Performance figures 113 */ 114struct tftp_stats { 115 size_t amount; 116 int rollovers; 117 uint32_t blocks; 118 int retries; 119 struct timeval tstart; 120 struct timeval tstop; 121}; 122 123void stats_init(struct tftp_stats *ts); 124void printstats(const char *direction, int verbose, struct tftp_stats *ts); 125