/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (C) 2008 Edwin Groothuis. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627/*28*/29#define TIMEOUT 530#define MAX_TIMEOUTS 53132/* Generic values */33#define MAXSEGSIZE 65464 /* Maximum size of the data segment */34#define MAXPKTSIZE (MAXSEGSIZE + 4) /* Maximum size of the packet */3536/* For the blksize option */37#define BLKSIZE_MIN 8 /* Minimum size of the data segment */38#define BLKSIZE_MAX MAXSEGSIZE /* Maximum size of the data segment */3940/* For the timeout option */41#define TIMEOUT_MIN 0 /* Minimum timeout value */42#define TIMEOUT_MAX 255 /* Maximum timeout value */43#define MIN_TIMEOUTS 34445/* For the windowsize option */46#define WINDOWSIZE 147#define WINDOWSIZE_MIN 148#define WINDOWSIZE_MAX 655354950extern int timeoutpacket;51extern int timeoutnetwork;52extern int maxtimeouts;53int settimeouts(int timeoutpacket, int timeoutnetwork, int maxtimeouts);5455extern uint16_t segsize;56extern uint16_t pktsize;57extern uint16_t windowsize;5859extern int acting_as_client;6061/*62*/63void unmappedaddr(struct sockaddr_in6 *sin6);64size_t get_field(int peer, char *buffer, size_t size);6566/*67* Packet types68*/69struct packettypes {70int value;71const char *const name;72};73extern struct packettypes packettypes[];74const char *packettype(int);7576/*77* RP_78*/79struct rp_errors {80int error;81const char *const desc;82};83extern struct rp_errors rp_errors[];84char *rp_strerror(int error);8586/*87* Debug features88*/89#define DEBUG_NONE 0x000090#define DEBUG_PACKETS 0x000191#define DEBUG_SIMPLE 0x000292#define DEBUG_OPTIONS 0x000493#define DEBUG_ACCESS 0x000894struct debugs {95int value;96const char *const name;97const char *const desc;98};99extern int debug;100extern struct debugs debugs[];101extern unsigned int packetdroppercentage;102int debug_find(char *s);103int debug_finds(char *s);104const char *debug_show(int d);105106/*107* Log routines108*/109#define DEBUG(s) tftp_log(LOG_DEBUG, "%s", s)110extern int tftp_logtostdout;111void tftp_openlog(const char *ident, int logopt, int facility);112void tftp_closelog(void);113void tftp_log(int priority, const char *message, ...) __printflike(2, 3);114115/*116* Performance figures117*/118struct tftp_stats {119size_t amount;120int rollovers;121uint32_t blocks;122int retries;123struct timeval tstart;124struct timeval tstop;125};126127void stats_init(struct tftp_stats *ts);128void printstats(const char *direction, int verbose, struct tftp_stats *ts);129130131