mirror of
https://github.com/sheumann/hush.git
synced 2025-02-26 22:29:56 +00:00
Merge branch 'master' of git+ssh://busybox.net/var/lib/git/busybox
This commit is contained in:
commit
5f118ff885
@ -211,7 +211,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
|
|||||||
# if ULONG_MAX > 0xffffffff
|
# if ULONG_MAX > 0xffffffff
|
||||||
/* "long" is long enough on this system */
|
/* "long" is long enough on this system */
|
||||||
typedef unsigned long uoff_t;
|
typedef unsigned long uoff_t;
|
||||||
# define XATOOFF(a) xatoul_range(a, 0, LONG_MAX)
|
# define XATOOFF(a) xatoul_range((a), 0, LONG_MAX)
|
||||||
/* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */
|
/* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */
|
||||||
# define BB_STRTOOFF bb_strtoul
|
# define BB_STRTOOFF bb_strtoul
|
||||||
# define STRTOOFF strtoul
|
# define STRTOOFF strtoul
|
||||||
@ -220,7 +220,7 @@ typedef unsigned long uoff_t;
|
|||||||
# else
|
# else
|
||||||
/* "long" is too short, need "long long" */
|
/* "long" is too short, need "long long" */
|
||||||
typedef unsigned long long uoff_t;
|
typedef unsigned long long uoff_t;
|
||||||
# define XATOOFF(a) xatoull_range(a, 0, LLONG_MAX)
|
# define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX)
|
||||||
# define BB_STRTOOFF bb_strtoull
|
# define BB_STRTOOFF bb_strtoull
|
||||||
# define STRTOOFF strtoull
|
# define STRTOOFF strtoull
|
||||||
# define OFF_FMT "ll"
|
# define OFF_FMT "ll"
|
||||||
@ -237,7 +237,7 @@ typedef unsigned long uoff_t;
|
|||||||
# define OFF_FMT "l"
|
# define OFF_FMT "l"
|
||||||
# else
|
# else
|
||||||
typedef unsigned long uoff_t;
|
typedef unsigned long uoff_t;
|
||||||
# define XATOOFF(a) xatoul_range(a, 0, LONG_MAX)
|
# define XATOOFF(a) xatoul_range((a), 0, LONG_MAX)
|
||||||
# define BB_STRTOOFF bb_strtoul
|
# define BB_STRTOOFF bb_strtoul
|
||||||
# define STRTOOFF strtol
|
# define STRTOOFF strtol
|
||||||
# define OFF_FMT "l"
|
# define OFF_FMT "l"
|
||||||
@ -245,6 +245,12 @@ typedef unsigned long uoff_t;
|
|||||||
#endif
|
#endif
|
||||||
/* scary. better ideas? (but do *test* them first!) */
|
/* scary. better ideas? (but do *test* them first!) */
|
||||||
#define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1)))
|
#define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1)))
|
||||||
|
/* Users report bionic to use 32-bit off_t even if LARGEFILE support is requested.
|
||||||
|
* We misdetected that. Don't let it build:
|
||||||
|
*/
|
||||||
|
struct BUG_off_t_size_is_misdetected {
|
||||||
|
char BUG_off_t_size_is_misdetected[sizeof(off_t) == sizeof(uoff_t) ? 1 : -1];
|
||||||
|
};
|
||||||
|
|
||||||
/* Some useful definitions */
|
/* Some useful definitions */
|
||||||
#undef FALSE
|
#undef FALSE
|
||||||
|
25
libbb/dump.c
25
libbb/dump.c
@ -71,7 +71,8 @@ static NOINLINE int bb_dump_size(FS *fs)
|
|||||||
* skip any special chars -- save precision in
|
* skip any special chars -- save precision in
|
||||||
* case it's a %s format.
|
* case it's a %s format.
|
||||||
*/
|
*/
|
||||||
while (strchr(index_str + 1, *++fmt));
|
while (strchr(index_str + 1, *++fmt))
|
||||||
|
continue;
|
||||||
if (*fmt == '.' && isdigit(*++fmt)) {
|
if (*fmt == '.' && isdigit(*++fmt)) {
|
||||||
prec = atoi(fmt);
|
prec = atoi(fmt);
|
||||||
while (isdigit(*++fmt))
|
while (isdigit(*++fmt))
|
||||||
@ -99,8 +100,8 @@ static NOINLINE int bb_dump_size(FS *fs)
|
|||||||
static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs)
|
static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs)
|
||||||
{
|
{
|
||||||
enum { NOTOKAY, USEBCNT, USEPREC } sokay;
|
enum { NOTOKAY, USEBCNT, USEPREC } sokay;
|
||||||
PR *pr;
|
|
||||||
FU *fu;
|
FU *fu;
|
||||||
|
PR *pr;
|
||||||
char *p1, *p2, *p3;
|
char *p1, *p2, *p3;
|
||||||
char savech, *fmtp;
|
char savech, *fmtp;
|
||||||
const char *byte_count_str;
|
const char *byte_count_str;
|
||||||
@ -292,16 +293,18 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs)
|
|||||||
* interprets any data at all, and has no iteration count,
|
* interprets any data at all, and has no iteration count,
|
||||||
* repeat it as necessary.
|
* repeat it as necessary.
|
||||||
*
|
*
|
||||||
* if, rep count is greater than 1, no trailing whitespace
|
* if rep count is greater than 1, no trailing whitespace
|
||||||
* gets output from the last iteration of the format unit.
|
* gets output from the last iteration of the format unit.
|
||||||
*/
|
*/
|
||||||
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
|
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
|
||||||
if (!fu->nextfu && fs->bcnt < dumper->blocksize
|
if (!fu->nextfu
|
||||||
&& !(fu->flags & F_SETREP) && fu->bcnt
|
&& fs->bcnt < dumper->blocksize
|
||||||
|
&& !(fu->flags & F_SETREP)
|
||||||
|
&& fu->bcnt
|
||||||
) {
|
) {
|
||||||
fu->reps += (dumper->blocksize - fs->bcnt) / fu->bcnt;
|
fu->reps += (dumper->blocksize - fs->bcnt) / fu->bcnt;
|
||||||
}
|
}
|
||||||
if (fu->reps > 1) {
|
if (fu->reps > 1 && fu->nextpr) {
|
||||||
for (pr = fu->nextpr;; pr = pr->nextpr)
|
for (pr = fu->nextpr;; pr = pr->nextpr)
|
||||||
if (!pr->nextpr)
|
if (!pr->nextpr)
|
||||||
break;
|
break;
|
||||||
@ -721,7 +724,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
|
|||||||
p = fmt;
|
p = fmt;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
p = skip_whitespace(p);
|
p = skip_whitespace(p);
|
||||||
if (!*p) {
|
if (*p == '\0') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -749,7 +752,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
|
|||||||
|
|
||||||
/* skip slash and trailing white space */
|
/* skip slash and trailing white space */
|
||||||
if (*p == '/') {
|
if (*p == '/') {
|
||||||
p = skip_whitespace(++p);
|
p = skip_whitespace(p + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* byte count */
|
/* byte count */
|
||||||
@ -763,7 +766,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
|
|||||||
}
|
}
|
||||||
tfu->bcnt = atoi(savep);
|
tfu->bcnt = atoi(savep);
|
||||||
/* skip trailing white space */
|
/* skip trailing white space */
|
||||||
p = skip_whitespace(++p);
|
p = skip_whitespace(p + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* format */
|
/* format */
|
||||||
@ -771,7 +774,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
|
|||||||
bb_error_msg_and_die("bad format {%s}", fmt);
|
bb_error_msg_and_die("bad format {%s}", fmt);
|
||||||
}
|
}
|
||||||
for (savep = ++p; *p != '"';) {
|
for (savep = ++p; *p != '"';) {
|
||||||
if (*p++ == 0) {
|
if (*p++ == '\0') {
|
||||||
bb_error_msg_and_die("bad format {%s}", fmt);
|
bb_error_msg_and_die("bad format {%s}", fmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -782,7 +785,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt)
|
|||||||
|
|
||||||
/* alphabetic escape sequences have to be done in place */
|
/* alphabetic escape sequences have to be done in place */
|
||||||
for (p2 = p1;; ++p1, ++p2) {
|
for (p2 = p1;; ++p1, ++p2) {
|
||||||
if (!*p1) {
|
if (*p1 == '\0') {
|
||||||
*p2 = *p1;
|
*p2 = *p1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ static char* FAST_FUNC parse_url(char *url, char **user, char **pass)
|
|||||||
void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol)
|
void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol)
|
||||||
{
|
{
|
||||||
enum {
|
enum {
|
||||||
SRC_BUF_SIZE = 45, /* This *MUST* be a multiple of 3 */
|
SRC_BUF_SIZE = 57, /* This *MUST* be a multiple of 3 */
|
||||||
DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3),
|
DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3),
|
||||||
};
|
};
|
||||||
#define src_buf text
|
#define src_buf text
|
||||||
|
@ -16,22 +16,15 @@ struct globals {
|
|||||||
char *pass;
|
char *pass;
|
||||||
FILE *fp0; // initial stdin
|
FILE *fp0; // initial stdin
|
||||||
char *opt_charset;
|
char *opt_charset;
|
||||||
char *content_type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define G (*ptr_to_globals)
|
#define G (*ptr_to_globals)
|
||||||
#define timeout (G.timeout )
|
#define timeout (G.timeout )
|
||||||
#define verbose (G.verbose )
|
#define verbose (G.verbose )
|
||||||
#define opts (G.opts )
|
#define opts (G.opts )
|
||||||
//#define user (G.user )
|
|
||||||
//#define pass (G.pass )
|
|
||||||
//#define fp0 (G.fp0 )
|
|
||||||
//#define opt_charset (G.opt_charset)
|
|
||||||
//#define content_type (G.content_type)
|
|
||||||
#define INIT_G() do { \
|
#define INIT_G() do { \
|
||||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
||||||
G.opt_charset = (char *)CONFIG_FEATURE_MIME_CHARSET; \
|
G.opt_charset = (char *)CONFIG_FEATURE_MIME_CHARSET; \
|
||||||
G.content_type = (char *)"text/plain"; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
//char FAST_FUNC *parse_url(char *url, char **user, char **pass);
|
//char FAST_FUNC *parse_url(char *url, char **user, char **pass);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/* vi: set sw=4 ts=4: */
|
/* vi: set sw=4 ts=4: */
|
||||||
/*
|
/*
|
||||||
* makemime: create MIME-encoded message
|
* makemime: create MIME-encoded message
|
||||||
* reformime: parse MIME-encoded message
|
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
|
* Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
|
||||||
*
|
*
|
||||||
@ -135,19 +134,42 @@ Content-Transfer-Encoding: 7bit
|
|||||||
//usage: "\n -o FILE Output. Default: stdout"
|
//usage: "\n -o FILE Output. Default: stdout"
|
||||||
//usage: "\n -a HDR Add header. Examples:"
|
//usage: "\n -a HDR Add header. Examples:"
|
||||||
//usage: "\n \"From: user@host.org\", \"Date: `date -R`\""
|
//usage: "\n \"From: user@host.org\", \"Date: `date -R`\""
|
||||||
//usage: "\n -c CT Content type. Default: text/plain"
|
//usage: "\n -c CT Content type. Default: application/octet-stream"
|
||||||
//usage: "\n -C CS Charset. Default: " CONFIG_FEATURE_MIME_CHARSET
|
//usage: "\n -C CS Charset. Default: " CONFIG_FEATURE_MIME_CHARSET
|
||||||
/* //usage: "\n -e ENC Transfer encoding. Ignored. base64 is assumed" */
|
/* //usage: "\n -e ENC Transfer encoding. Ignored. base64 is assumed" */
|
||||||
//usage: "\n"
|
//usage: "\n"
|
||||||
//usage: "\nOther options are silently ignored"
|
//usage: "\nOther options are silently ignored"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -c [Content-Type] should create just one MIME section
|
||||||
|
* with "Content-Type:", "Content-Transfer-Encoding:", and HDR from "-a HDR".
|
||||||
|
* NB: without "Content-Disposition:" auto-added, unlike we do now
|
||||||
|
* NB2: -c has *optional* param which nevertheless _can_ be specified after a space :(
|
||||||
|
*
|
||||||
|
* -m [multipart/mixed] should create multipart MIME section
|
||||||
|
* with "Content-Type:", "Content-Transfer-Encoding:", and HDR from "-a HDR",
|
||||||
|
* and add FILE to it _verbatim_:
|
||||||
|
* HEADERS
|
||||||
|
*
|
||||||
|
* --=_1_1321709112_1605
|
||||||
|
* FILE_CONTENTS
|
||||||
|
* --=_1_1321709112_1605
|
||||||
|
* without any encoding of FILE_CONTENTS. (Basically, it expects that FILE
|
||||||
|
* is the result of "makemime -c").
|
||||||
|
*
|
||||||
|
* -j MULTIPART_FILE1 SINGLE_FILE2 should output MULTIPART_FILE1 + SINGLE_FILE2
|
||||||
|
*
|
||||||
|
* Our current behavior is a mutant "-m + -c + -j" one: we create multipart MIME
|
||||||
|
* and we put "-c" encoded FILEs into many multipart sections.
|
||||||
|
*/
|
||||||
|
|
||||||
int makemime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int makemime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int makemime_main(int argc UNUSED_PARAM, char **argv)
|
int makemime_main(int argc UNUSED_PARAM, char **argv)
|
||||||
{
|
{
|
||||||
llist_t *opt_headers = NULL, *l;
|
llist_t *opt_headers = NULL, *l;
|
||||||
const char *opt_output;
|
const char *opt_output;
|
||||||
|
const char *content_type = "application/octet-stream";
|
||||||
#define boundary opt_output
|
#define boundary opt_output
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OPT_c = 1 << 0, // create (non-multipart) section
|
OPT_c = 1 << 0, // create (non-multipart) section
|
||||||
OPT_e = 1 << 1, // Content-Transfer-Encoding. Ignored. Assumed base64
|
OPT_e = 1 << 1, // Content-Transfer-Encoding. Ignored. Assumed base64
|
||||||
@ -164,8 +186,8 @@ int makemime_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
// parse options
|
// parse options
|
||||||
opt_complementary = "a::";
|
opt_complementary = "a::";
|
||||||
opts = getopt32(argv,
|
opts = getopt32(argv,
|
||||||
"c:e:o:C:N:a:", //:m:j:",
|
"c:e:o:C:N:a:", // "m:j:",
|
||||||
&G.content_type, NULL, &opt_output, &G.opt_charset, NULL, &opt_headers //, NULL, NULL
|
&content_type, NULL, &opt_output, &G.opt_charset, NULL, &opt_headers //, NULL, NULL
|
||||||
);
|
);
|
||||||
//argc -= optind;
|
//argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
@ -202,7 +224,7 @@ int makemime_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
"Content-Disposition: inline; filename=\"%s\"\n"
|
"Content-Disposition: inline; filename=\"%s\"\n"
|
||||||
"Content-Transfer-Encoding: base64\n"
|
"Content-Transfer-Encoding: base64\n"
|
||||||
, boundary
|
, boundary
|
||||||
, G.content_type
|
, content_type
|
||||||
, G.opt_charset
|
, G.opt_charset
|
||||||
, bb_get_last_path_component_strip(*argv)
|
, bb_get_last_path_component_strip(*argv)
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* vi: set sw=4 ts=4: */
|
/* vi: set sw=4 ts=4: */
|
||||||
/*
|
/*
|
||||||
* makemime: create MIME-encoded message
|
|
||||||
* reformime: parse MIME-encoded message
|
* reformime: parse MIME-encoded message
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
|
* Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
|
||||||
|
@ -281,17 +281,19 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
// analyze headers
|
// analyze headers
|
||||||
// To: or Cc: headers add recipients
|
// To: or Cc: headers add recipients
|
||||||
if (0 == strncasecmp("To:", s, 3) || 0 == strncasecmp("Bcc:" + 1, s, 3)) {
|
if (opts & OPT_t) {
|
||||||
rcptto(sane_address(s+3));
|
if (0 == strncasecmp("To:", s, 3) || 0 == strncasecmp("Bcc:" + 1, s, 3)) {
|
||||||
goto addheader;
|
rcptto(sane_address(s+3));
|
||||||
|
goto addheader;
|
||||||
|
}
|
||||||
|
// Bcc: header adds blind copy (hidden) recipient
|
||||||
|
if (0 == strncasecmp("Bcc:", s, 4)) {
|
||||||
|
rcptto(sane_address(s+4));
|
||||||
|
free(s);
|
||||||
|
continue; // N.B. Bcc: vanishes from headers!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Bcc: header adds blind copy (hidden) recipient
|
if (strchr(s, ':') || (list && isspace(s[0]))) {
|
||||||
if (0 == strncasecmp("Bcc:", s, 4)) {
|
|
||||||
rcptto(sane_address(s+4));
|
|
||||||
free(s);
|
|
||||||
// N.B. Bcc: vanishes from headers!
|
|
||||||
} else
|
|
||||||
if (strchr(s, ':') || (list && skip_whitespace(s) != s)) {
|
|
||||||
// other headers go verbatim
|
// other headers go verbatim
|
||||||
// N.B. RFC2822 2.2.3 "Long Header Fields" allows for headers to occupy several lines.
|
// N.B. RFC2822 2.2.3 "Long Header Fields" allows for headers to occupy several lines.
|
||||||
// Continuation is denoted by prefixing additional lines with whitespace(s).
|
// Continuation is denoted by prefixing additional lines with whitespace(s).
|
||||||
|
@ -539,3 +539,22 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg)
|
|||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* note: ip is a pointer to an IPv6 in network order, possibly misaliged */
|
||||||
|
int FAST_FUNC sprint_nip6(char *dest, /*const char *pre,*/ const uint8_t *ip)
|
||||||
|
{
|
||||||
|
char hexstrbuf[16 * 2];
|
||||||
|
bin2hex(hexstrbuf, (void*)ip, 16);
|
||||||
|
return sprintf(dest, /* "%s" */
|
||||||
|
"%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s",
|
||||||
|
/* pre, */
|
||||||
|
hexstrbuf + 0 * 4,
|
||||||
|
hexstrbuf + 1 * 4,
|
||||||
|
hexstrbuf + 2 * 4,
|
||||||
|
hexstrbuf + 3 * 4,
|
||||||
|
hexstrbuf + 4 * 4,
|
||||||
|
hexstrbuf + 5 * 4,
|
||||||
|
hexstrbuf + 6 * 4,
|
||||||
|
hexstrbuf + 7 * 4
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -308,6 +308,9 @@ int arpping(uint32_t test_nip,
|
|||||||
uint8_t *from_mac,
|
uint8_t *from_mac,
|
||||||
const char *interface) FAST_FUNC;
|
const char *interface) FAST_FUNC;
|
||||||
|
|
||||||
|
/* note: ip is a pointer to an IPv6 in network order, possibly misaliged */
|
||||||
|
int sprint_nip6(char *dest, /*const char *pre,*/ const uint8_t *ip) FAST_FUNC;
|
||||||
|
|
||||||
POP_SAVED_FUNCTION_VISIBILITY
|
POP_SAVED_FUNCTION_VISIBILITY
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,11 +81,16 @@ struct d6_option {
|
|||||||
#define D6_OPT_RECONF_MSG 19
|
#define D6_OPT_RECONF_MSG 19
|
||||||
#define D6_OPT_RECONF_ACCEPT 20
|
#define D6_OPT_RECONF_ACCEPT 20
|
||||||
|
|
||||||
|
#define D6_OPT_IA_PD 25
|
||||||
|
#define D6_OPT_IAPREFIX 26
|
||||||
|
|
||||||
/*** Other shared functions ***/
|
/*** Other shared functions ***/
|
||||||
|
|
||||||
struct client6_data_t {
|
struct client6_data_t {
|
||||||
struct d6_option *server_id;
|
struct d6_option *server_id;
|
||||||
struct d6_option *ia_na;
|
struct d6_option *ia_na;
|
||||||
|
char **env_ptr;
|
||||||
|
unsigned env_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)]))
|
#define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)]))
|
||||||
|
@ -129,32 +129,114 @@ static void *d6_store_blob(void *dst, const void *src, unsigned len)
|
|||||||
|
|
||||||
/*** Script execution code ***/
|
/*** Script execution code ***/
|
||||||
|
|
||||||
/* put all the parameters into the environment */
|
static char** new_env(void)
|
||||||
static char **fill_envp(struct d6_packet *packet
|
{
|
||||||
UNUSED_PARAM
|
client6_data.env_ptr = xrealloc_vector(client6_data.env_ptr, 3, client6_data.env_idx);
|
||||||
)
|
return &client6_data.env_ptr[client6_data.env_idx++];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* put all the parameters into the environment */
|
||||||
|
static void option_to_env(uint8_t *option, uint8_t *option_end)
|
||||||
|
{
|
||||||
|
/* "length minus 4" */
|
||||||
|
int len_m4 = option_end - option - 4;
|
||||||
|
while (len_m4 >= 0) {
|
||||||
|
uint32_t v32;
|
||||||
|
char ipv6str[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")];
|
||||||
|
|
||||||
|
if (option[0] != 0 || option[2] != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (option[1]) {
|
||||||
|
//case D6_OPT_CLIENTID:
|
||||||
|
//case D6_OPT_SERVERID:
|
||||||
|
case D6_OPT_IA_NA:
|
||||||
|
case D6_OPT_IA_PD:
|
||||||
|
option_to_env(option + 16, option + 4 + option[3]);
|
||||||
|
break;
|
||||||
|
//case D6_OPT_IA_TA:
|
||||||
|
case D6_OPT_IAADDR:
|
||||||
|
/* 0 1 2 3
|
||||||
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | OPTION_IAADDR | option-len |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | |
|
||||||
|
* | IPv6 address |
|
||||||
|
* | |
|
||||||
|
* | |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | preferred-lifetime |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | valid-lifetime |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
sprint_nip6(ipv6str, option + 4);
|
||||||
|
*new_env() = xasprintf("ipv6=%s", ipv6str);
|
||||||
|
|
||||||
|
move_from_unaligned32(v32, option + 4 + 16 + 4);
|
||||||
|
*new_env() = xasprintf("lease=%u", (unsigned)v32);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//case D6_OPT_ORO:
|
||||||
|
//case D6_OPT_PREFERENCE:
|
||||||
|
//case D6_OPT_ELAPSED_TIME:
|
||||||
|
//case D6_OPT_RELAY_MSG:
|
||||||
|
//case D6_OPT_AUTH:
|
||||||
|
//case D6_OPT_UNICAST:
|
||||||
|
//case D6_OPT_STATUS_CODE:
|
||||||
|
//case D6_OPT_RAPID_COMMIT:
|
||||||
|
//case D6_OPT_USER_CLASS:
|
||||||
|
//case D6_OPT_VENDOR_CLASS:
|
||||||
|
//case D6_OPT_VENDOR_OPTS:
|
||||||
|
//case D6_OPT_INTERFACE_ID:
|
||||||
|
//case D6_OPT_RECONF_MSG:
|
||||||
|
//case D6_OPT_RECONF_ACCEPT:
|
||||||
|
|
||||||
|
case D6_OPT_IAPREFIX:
|
||||||
|
/* 0 1 2 3
|
||||||
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | OPTION_IAPREFIX | option-length |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | preferred-lifetime |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | valid-lifetime |
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | prefix-length | |
|
||||||
|
* +-+-+-+-+-+-+-+-+ IPv6 prefix |
|
||||||
|
* | (16 octets) |
|
||||||
|
* | |
|
||||||
|
* | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
* | |
|
||||||
|
* +-+-+-+-+-+-+-+-+
|
||||||
|
*/
|
||||||
|
//move_from_unaligned32(v32, option + 4 + 4);
|
||||||
|
//*new_env() = xasprintf("lease=%u", (unsigned)v32);
|
||||||
|
|
||||||
|
sprint_nip6(ipv6str, option + 4 + 4 + 1);
|
||||||
|
*new_env() = xasprintf("ipv6prefix=%s/%u", ipv6str, (unsigned)(option[4 + 4]));
|
||||||
|
}
|
||||||
|
option += 4 + option[3];
|
||||||
|
len_m4 -= 4 + option[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static char **fill_envp(struct d6_packet *packet)
|
||||||
{
|
{
|
||||||
int envc;
|
|
||||||
char **envp, **curr;
|
char **envp, **curr;
|
||||||
|
|
||||||
#define BITMAP unsigned
|
client6_data.env_ptr = NULL;
|
||||||
#define BBITS (sizeof(BITMAP) * 8)
|
client6_data.env_idx = 0;
|
||||||
#define BMASK(i) (1 << (i & (sizeof(BITMAP) * 8 - 1)))
|
|
||||||
#define FOUND_OPTS(i) (found_opts[(unsigned)i / BBITS])
|
|
||||||
///BITMAP found_opts[256 / BBITS];
|
|
||||||
|
|
||||||
///memset(found_opts, 0, sizeof(found_opts));
|
*new_env() = xasprintf("interface=%s", client_config.interface);
|
||||||
|
|
||||||
/* We need 2 elements for:
|
if (packet)
|
||||||
* "interface=IFACE"
|
option_to_env(packet->d6_options, packet->d6_options + sizeof(packet->d6_options));
|
||||||
* terminating NULL
|
|
||||||
*/
|
|
||||||
envc = 2;
|
|
||||||
|
|
||||||
curr = envp = xzalloc(sizeof(envp[0]) * envc);
|
envp = curr = client6_data.env_ptr;
|
||||||
|
while (*curr)
|
||||||
*curr = xasprintf("interface=%s", client_config.interface);
|
putenv(*curr++);
|
||||||
putenv(*curr++);
|
|
||||||
|
|
||||||
return envp;
|
return envp;
|
||||||
}
|
}
|
||||||
@ -1329,19 +1411,19 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
free(client6_data.ia_na);
|
free(client6_data.ia_na);
|
||||||
client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA);
|
client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA);
|
||||||
if (!client6_data.ia_na) {
|
if (!client6_data.ia_na) {
|
||||||
bb_error_msg("no lease time, ignoring packet");
|
bb_error_msg("no %s option, ignoring packet", "IA_NA");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) {
|
if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) {
|
||||||
bb_error_msg("IA_NA option is too short:%d bytes", client6_data.ia_na->len);
|
bb_error_msg("IA_NA option is too short:%d bytes", client6_data.ia_na->len);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
iaaddr = d6_find_option(client6_data.ia_na->data,
|
iaaddr = d6_find_option(client6_data.ia_na->data + 4 + 4 + 4,
|
||||||
client6_data.ia_na->data + client6_data.ia_na->len,
|
client6_data.ia_na->data + client6_data.ia_na->len,
|
||||||
D6_OPT_IAADDR
|
D6_OPT_IAADDR
|
||||||
);
|
);
|
||||||
if (!iaaddr) {
|
if (!iaaddr) {
|
||||||
bb_error_msg("no lease time, ignoring packet");
|
bb_error_msg("no %s option, ignoring packet", "IAADDR");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (iaaddr->len < (16 + 4 + 4)) {
|
if (iaaddr->len < (16 + 4 + 4)) {
|
||||||
|
@ -123,24 +123,6 @@ static int sprint_nip(char *dest, const char *pre, const uint8_t *ip)
|
|||||||
return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]);
|
return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sprint_nip6(char *dest, /*const char *pre,*/ const uint8_t *ip)
|
|
||||||
{
|
|
||||||
char hexstrbuf[16 * 2];
|
|
||||||
bin2hex(hexstrbuf, (void*)ip, 16);
|
|
||||||
return sprintf(dest, /* "%s" */
|
|
||||||
"%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s",
|
|
||||||
/* pre, */
|
|
||||||
hexstrbuf + 0 * 4,
|
|
||||||
hexstrbuf + 1 * 4,
|
|
||||||
hexstrbuf + 2 * 4,
|
|
||||||
hexstrbuf + 3 * 4,
|
|
||||||
hexstrbuf + 4 * 4,
|
|
||||||
hexstrbuf + 5 * 4,
|
|
||||||
hexstrbuf + 6 * 4,
|
|
||||||
hexstrbuf + 7 * 4
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* really simple implementation, just count the bits */
|
/* really simple implementation, just count the bits */
|
||||||
static int mton(uint32_t mask)
|
static int mton(uint32_t mask)
|
||||||
{
|
{
|
||||||
@ -744,7 +726,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
|
|||||||
#if ENABLE_FEATURE_UDHCPC_ARPING
|
#if ENABLE_FEATURE_UDHCPC_ARPING
|
||||||
/* Broadcast a DHCP decline message */
|
/* Broadcast a DHCP decline message */
|
||||||
/* NOINLINE: limit stack usage in caller */
|
/* NOINLINE: limit stack usage in caller */
|
||||||
static NOINLINE int send_decline(uint32_t xid, uint32_t server, uint32_t requested)
|
static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t requested)
|
||||||
{
|
{
|
||||||
struct dhcp_packet packet;
|
struct dhcp_packet packet;
|
||||||
|
|
||||||
@ -753,12 +735,14 @@ static NOINLINE int send_decline(uint32_t xid, uint32_t server, uint32_t request
|
|||||||
*/
|
*/
|
||||||
init_packet(&packet, DHCPDECLINE);
|
init_packet(&packet, DHCPDECLINE);
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* RFC 2131 says DHCPDECLINE's xid is randomly selected by client,
|
/* RFC 2131 says DHCPDECLINE's xid is randomly selected by client,
|
||||||
* but in case the server is buggy and wants DHCPDECLINE's xid
|
* but in case the server is buggy and wants DHCPDECLINE's xid
|
||||||
* to match the xid which started entire handshake,
|
* to match the xid which started entire handshake,
|
||||||
* we use the same xid we used in initial DHCPDISCOVER:
|
* we use the same xid we used in initial DHCPDISCOVER:
|
||||||
*/
|
*/
|
||||||
packet.xid = xid;
|
packet.xid = xid;
|
||||||
|
#endif
|
||||||
/* DHCPDECLINE uses "requested ip", not ciaddr, to store offered IP */
|
/* DHCPDECLINE uses "requested ip", not ciaddr, to store offered IP */
|
||||||
udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested);
|
udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested);
|
||||||
|
|
||||||
@ -1149,7 +1133,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
int discover_retries = 3;
|
int discover_retries = 3;
|
||||||
uint32_t server_addr = server_addr; /* for compiler */
|
uint32_t server_addr = server_addr; /* for compiler */
|
||||||
uint32_t requested_ip = 0;
|
uint32_t requested_ip = 0;
|
||||||
uint32_t xid = 0;
|
uint32_t xid = xid; /* for compiler */
|
||||||
int packet_num;
|
int packet_num;
|
||||||
int timeout; /* must be signed */
|
int timeout; /* must be signed */
|
||||||
unsigned already_waited_sec;
|
unsigned already_waited_sec;
|
||||||
@ -1538,7 +1522,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INIT_SELECTING:
|
case INIT_SELECTING:
|
||||||
/* Must be a DHCPOFFER to one of our xid's */
|
/* Must be a DHCPOFFER */
|
||||||
if (*message == DHCPOFFER) {
|
if (*message == DHCPOFFER) {
|
||||||
/* What exactly is server's IP? There are several values.
|
/* What exactly is server's IP? There are several values.
|
||||||
* Example DHCP offer captured with tchdump:
|
* Example DHCP offer captured with tchdump:
|
||||||
@ -1618,7 +1602,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
) {
|
) {
|
||||||
bb_info_msg("Offered address is in use "
|
bb_info_msg("Offered address is in use "
|
||||||
"(got ARP reply), declining");
|
"(got ARP reply), declining");
|
||||||
send_decline(xid, server_addr, packet.yiaddr);
|
send_decline(/*xid,*/ server_addr, packet.yiaddr);
|
||||||
|
|
||||||
if (state != REQUESTING)
|
if (state != REQUESTING)
|
||||||
udhcp_run_script(NULL, "deconfig");
|
udhcp_run_script(NULL, "deconfig");
|
||||||
@ -1655,6 +1639,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
opt = ((opt & ~OPT_b) | OPT_f);
|
opt = ((opt & ~OPT_b) | OPT_f);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
/* make future renew packets use different xid */
|
||||||
|
/* xid = random_xid(); ...but why bother? */
|
||||||
already_waited_sec = 0;
|
already_waited_sec = 0;
|
||||||
continue; /* back to main loop */
|
continue; /* back to main loop */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user