1207614Simp/* 2207614Simp * Copyright (C) 2008 Edwin Groothuis. All rights reserved. 3207614Simp * 4207614Simp * Redistribution and use in source and binary forms, with or without 5207614Simp * modification, are permitted provided that the following conditions 6207614Simp * are met: 7207614Simp * 1. Redistributions of source code must retain the above copyright 8207614Simp * notice, this list of conditions and the following disclaimer. 9207614Simp * 2. Redistributions in binary form must reproduce the above copyright 10207614Simp * notice, this list of conditions and the following disclaimer in the 11207614Simp * documentation and/or other materials provided with the distribution. 12207614Simp * 13207614Simp * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14207614Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15207614Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16207614Simp * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 17207614Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18207614Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19207614Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20207614Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21207614Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22207614Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23207614Simp * SUCH DAMAGE. 24207614Simp */ 25207614Simp 26207614Simp#include <sys/cdefs.h> 27207614Simp__FBSDID("$FreeBSD$"); 28207614Simp 29207614Simp/* 30207614Simp */ 31207614Simp#define TIMEOUT 5 32207614Simp#define MAX_TIMEOUTS 5 33207614Simp 34207614Simp/* Generic values */ 35207614Simp#define MAXSEGSIZE 65464 /* Maximum size of the data segment */ 36207614Simp#define MAXPKTSIZE (MAXSEGSIZE + 4) /* Maximum size of the packet */ 37207614Simp 38207614Simp/* For the blksize option */ 39229780Suqs#define BLKSIZE_MIN 8 /* Minimum size of the data segment */ 40207614Simp#define BLKSIZE_MAX MAXSEGSIZE /* Maximum size of the data segment */ 41207614Simp 42207614Simp/* For the timeout option */ 43229780Suqs#define TIMEOUT_MIN 0 /* Minimum timeout value */ 44207614Simp#define TIMEOUT_MAX 255 /* Maximum timeout value */ 45207614Simp#define MIN_TIMEOUTS 3 46207614Simp 47207614Simpextern int timeoutpacket; 48207614Simpextern int timeoutnetwork; 49207614Simpextern int maxtimeouts; 50207614Simpint settimeouts(int timeoutpacket, int timeoutnetwork, int maxtimeouts); 51207614Simp 52207614Simpextern uint16_t segsize; 53207614Simpextern uint16_t pktsize; 54207614Simp 55207614Simpextern int acting_as_client; 56207614Simp 57207614Simp/* 58207614Simp */ 59207614Simpvoid unmappedaddr(struct sockaddr_in6 *sin6); 60207614Simpssize_t get_field(int peer, char *buffer, ssize_t size); 61207614Simp 62207614Simp/* 63207614Simp * Packet types 64207614Simp */ 65207614Simpstruct packettypes { 66207614Simp int value; 67213099Smarius const char *const name; 68207614Simp}; 69207614Simpextern struct packettypes packettypes[]; 70213099Smariusconst char *packettype(int); 71207614Simp 72207614Simp/* 73207614Simp * RP_ 74207614Simp */ 75207614Simpstruct rp_errors { 76207614Simp int error; 77213099Smarius const char *const desc; 78207614Simp}; 79207614Simpextern struct rp_errors rp_errors[]; 80207614Simpchar *rp_strerror(int error); 81207614Simp 82207614Simp/* 83207614Simp * Debug features 84207614Simp */ 85207614Simp#define DEBUG_NONE 0x0000 86207614Simp#define DEBUG_PACKETS 0x0001 87207614Simp#define DEBUG_SIMPLE 0x0002 88207614Simp#define DEBUG_OPTIONS 0x0004 89207614Simp#define DEBUG_ACCESS 0x0008 90207614Simpstruct debugs { 91207614Simp int value; 92213099Smarius const char *const name; 93213099Smarius const char *const desc; 94207614Simp}; 95207614Simpextern int debug; 96207614Simpextern struct debugs debugs[]; 97207614Simpextern int packetdroppercentage; 98207614Simpint debug_find(char *s); 99207614Simpint debug_finds(char *s); 100213099Smariusconst char *debug_show(int d); 101207614Simp 102207614Simp/* 103207614Simp * Log routines 104207614Simp */ 105207614Simp#define DEBUG(s) tftp_log(LOG_DEBUG, "%s", s) 106207614Simpextern int tftp_logtostdout; 107207614Simpvoid tftp_openlog(const char *ident, int logopt, int facility); 108207614Simpvoid tftp_closelog(void); 109246139Smariusvoid tftp_log(int priority, const char *message, ...) __printflike(2, 3); 110207614Simp 111207614Simp/* 112207614Simp * Performance figures 113207614Simp */ 114207614Simpstruct tftp_stats { 115207614Simp size_t amount; 116207614Simp int rollovers; 117207614Simp uint32_t blocks; 118207614Simp int retries; 119207614Simp struct timeval tstart; 120207614Simp struct timeval tstop; 121207614Simp}; 122207614Simp 123207614Simpvoid stats_init(struct tftp_stats *ts); 124207614Simpvoid printstats(const char *direction, int verbose, struct tftp_stats *ts); 125