tftp-utils.h revision 246139
131921Sbrian/* 231921Sbrian * Copyright (C) 2008 Edwin Groothuis. All rights reserved. 331921Sbrian * 431921Sbrian * Redistribution and use in source and binary forms, with or without 531921Sbrian * modification, are permitted provided that the following conditions 631921Sbrian * are met: 731921Sbrian * 1. Redistributions of source code must retain the above copyright 831921Sbrian * notice, this list of conditions and the following disclaimer. 931921Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1031921Sbrian * notice, this list of conditions and the following disclaimer in the 1131921Sbrian * documentation and/or other materials provided with the distribution. 1231921Sbrian * 1331921Sbrian * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1431921Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1531921Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1631921Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 1731921Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1831921Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1931921Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2031921Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2131921Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2231921Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2331921Sbrian * SUCH DAMAGE. 2431921Sbrian */ 2531921Sbrian 2650479Speter#include <sys/cdefs.h> 2731196Sbrian__FBSDID("$FreeBSD: head/libexec/tftpd/tftp-utils.h 246139 2013-01-31 00:02:36Z marius $"); 2831196Sbrian 2943313Sbrian/* 3078410Sbrian */ 3178410Sbrian#define TIMEOUT 5 3251447Sbrian#define MAX_TIMEOUTS 5 3337192Sbrian 3449434Sbrian/* Generic values */ 3578410Sbrian#define MAXSEGSIZE 65464 /* Maximum size of the data segment */ 3631195Sbrian#define MAXPKTSIZE (MAXSEGSIZE + 4) /* Maximum size of the packet */ 3738201Sbrian 3831195Sbrian/* For the blksize option */ 3936285Sbrian#define BLKSIZE_MIN 8 /* Minimum size of the data segment */ 4036285Sbrian#define BLKSIZE_MAX MAXSEGSIZE /* Maximum size of the data segment */ 4136285Sbrian 4231195Sbrian/* For the timeout option */ 4346085Sbrian#define TIMEOUT_MIN 0 /* Minimum timeout value */ 4431195Sbrian#define TIMEOUT_MAX 255 /* Maximum timeout value */ 4549472Sbrian#define MIN_TIMEOUTS 3 4631195Sbrian 4749472Sbrianextern int timeoutpacket; 4873988Sbrianextern int timeoutnetwork; 4946686Sbrianextern int maxtimeouts; 5046086Sbrianint settimeouts(int timeoutpacket, int timeoutnetwork, int maxtimeouts); 5146086Sbrian 5246086Sbrianextern uint16_t segsize; 5331195Sbrianextern uint16_t pktsize; 5446686Sbrian 5531343Sbrianextern int acting_as_client; 5631343Sbrian 5773988Sbrian/* 5836285Sbrian */ 5936285Sbrianvoid unmappedaddr(struct sockaddr_in6 *sin6); 6031195Sbrianssize_t get_field(int peer, char *buffer, ssize_t size); 6131195Sbrian 6236285Sbrian/* 6336285Sbrian * Packet types 6436285Sbrian */ 6536285Sbrianstruct packettypes { 6681634Sbrian int value; 6736285Sbrian const char *const name; 6836285Sbrian}; 6936285Sbrianextern struct packettypes packettypes[]; 7036285Sbrianconst char *packettype(int); 7136285Sbrian 7236285Sbrian/* 7336285Sbrian * RP_ 7478410Sbrian */ 7543313Sbrianstruct rp_errors { 7643313Sbrian int error; 7743313Sbrian const char *const desc; 7881634Sbrian}; 7981634Sbrianextern struct rp_errors rp_errors[]; 8036285Sbrianchar *rp_strerror(int error); 8131195Sbrian 8231195Sbrian/* 8331195Sbrian * Debug features 8469303Sbrian */ 8531195Sbrian#define DEBUG_NONE 0x0000 8646086Sbrian#define DEBUG_PACKETS 0x0001 8746086Sbrian#define DEBUG_SIMPLE 0x0002 8846086Sbrian#define DEBUG_OPTIONS 0x0004 8998243Sbrian#define DEBUG_ACCESS 0x0008 9089422Sbrianstruct debugs { 9198243Sbrian int value; 9246086Sbrian const char *const name; 9346086Sbrian const char *const desc; 9446086Sbrian}; 9546086Sbrianextern int debug; 9646086Sbrianextern struct debugs debugs[]; 9746086Sbrianextern int packetdroppercentage; 9878410Sbrianint debug_find(char *s); 9946086Sbrianint debug_finds(char *s); 10046086Sbrianconst char *debug_show(int d); 10146086Sbrian 10246086Sbrian/* 10346086Sbrian * Log routines 10446086Sbrian */ 10531195Sbrian#define DEBUG(s) tftp_log(LOG_DEBUG, "%s", s) 10631195Sbrianextern int tftp_logtostdout; 10740561Sbrianvoid tftp_openlog(const char *ident, int logopt, int facility); 10838201Sbrianvoid tftp_closelog(void); 10978410Sbrianvoid tftp_log(int priority, const char *message, ...) __printflike(2, 3); 11098243Sbrian 11149434Sbrian/* 11249434Sbrian * Performance figures 11382048Sbrian */ 11431195Sbrianstruct tftp_stats { 11573988Sbrian size_t amount; 11636285Sbrian int rollovers; 11731195Sbrian uint32_t blocks; 11846086Sbrian int retries; 11931195Sbrian 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