]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/bio/bio_local.h
Update copyright year
[thirdparty/openssl.git] / crypto / bio / bio_local.h
CommitLineData
b1322259 1/*
fecb3aae 2 * Copyright 2005-2022 The OpenSSL Project Authors. All Rights Reserved.
b1322259 3 *
09abbca1 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
b1322259
RS
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
d5f9166b 10#include "internal/e_os.h"
0e97f1e1 11#include "internal/sockets.h"
28a0841b
RL
12
13/* BEGIN BIO_ADDRINFO/BIO_ADDR stuff. */
14
15#ifndef OPENSSL_NO_SOCK
16/*
17 * Throughout this file and b_addr.c, the existence of the macro
18 * AI_PASSIVE is used to detect the availability of struct addrinfo,
19 * getnameinfo() and getaddrinfo(). If that macro doesn't exist,
20 * we use our own implementation instead.
21 */
22
23/*
24 * It's imperative that these macros get defined before openssl/bio.h gets
25 * included. Otherwise, the AI_PASSIVE hack will not work properly.
26 * For clarity, we check for internal/cryptlib.h since it's a common header
27 * that also includes bio.h.
28 */
ae4186b0 29# ifdef OSSL_INTERNAL_CRYPTLIB_H
706457b7 30# error internal/cryptlib.h included before bio_local.h
28a0841b 31# endif
ae4186b0 32# ifdef OPENSSL_BIO_H
706457b7 33# error openssl/bio.h included before bio_local.h
28a0841b
RL
34# endif
35
36/*
37 * Undefine AF_UNIX on systems that define it but don't support it.
38 */
39# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VMS)
40# undef AF_UNIX
41# endif
42
43# ifdef AI_PASSIVE
fcd9c8c0
RL
44
45/*
46 * There's a bug in VMS C header file netdb.h, where struct addrinfo
47 * always is the P32 variant, but the functions that handle that structure,
48 * such as getaddrinfo() and freeaddrinfo() adapt to the initial pointer
49 * size. The easiest workaround is to force struct addrinfo to be the
50 * 64-bit variant when compiling in P64 mode.
51 */
52# if defined(OPENSSL_SYS_VMS) && __INITIAL_POINTER_SIZE == 64
53# define addrinfo __addrinfo64
54# endif
55
28a0841b
RL
56# define bio_addrinfo_st addrinfo
57# define bai_family ai_family
58# define bai_socktype ai_socktype
59# define bai_protocol ai_protocol
60# define bai_addrlen ai_addrlen
61# define bai_addr ai_addr
62# define bai_next ai_next
63# else
64struct bio_addrinfo_st {
65 int bai_family;
66 int bai_socktype;
67 int bai_protocol;
68 size_t bai_addrlen;
69 struct sockaddr *bai_addr;
70 struct bio_addrinfo_st *bai_next;
71};
72# endif
73
74union bio_addr_st {
75 struct sockaddr sa;
76# ifdef AF_INET6
29620124 77 struct sockaddr_in6 s_in6;
28a0841b 78# endif
29620124 79 struct sockaddr_in s_in;
28a0841b 80# ifdef AF_UNIX
29620124 81 struct sockaddr_un s_un;
28a0841b
RL
82# endif
83};
84#endif
85
86/* END BIO_ADDRINFO/BIO_ADDR stuff. */
87
88#include "internal/cryptlib.h"
176db6dc 89#include "internal/bio.h"
a935791d 90#include "internal/refcount.h"
a146ae55
MC
91
92typedef struct bio_f_buffer_ctx_struct {
93 /*-
94 * Buffers are setup like this:
95 *
96 * <---------------------- size ----------------------->
97 * +---------------------------------------------------+
98 * | consumed | remaining | free space |
99 * +---------------------------------------------------+
100 * <-- off --><------- len ------->
101 */
102 /*- BIO *bio; *//*
103 * this is now in the BIO struct
104 */
105 int ibuf_size; /* how big is the input buffer */
106 int obuf_size; /* how big is the output buffer */
107 char *ibuf; /* the char array */
108 int ibuf_len; /* how many bytes are in it */
109 int ibuf_off; /* write/read offset */
110 char *obuf; /* the char array */
111 int obuf_len; /* how many bytes are in it */
112 int obuf_off; /* write/read offset */
113} BIO_F_BUFFER_CTX;
114
115struct bio_st {
b0ee1de9 116 OSSL_LIB_CTX *libctx;
a146ae55
MC
117 const BIO_METHOD *method;
118 /* bio, mode, argp, argi, argl, ret */
0800318a 119#ifndef OPENSSL_NO_DEPRECATED_3_0
d07aee2c 120 BIO_callback_fn callback;
0800318a 121#endif
d07aee2c 122 BIO_callback_fn_ex callback_ex;
a146ae55
MC
123 char *cb_arg; /* first argument for the callback */
124 int init;
125 int shutdown;
126 int flags; /* extra storage */
127 int retry_reason;
128 int num;
129 void *ptr;
130 struct bio_st *next_bio; /* used by filter BIOs */
131 struct bio_st *prev_bio; /* used by filter BIOs */
2f545ae4 132 CRYPTO_REF_COUNT references;
a146ae55
MC
133 uint64_t num_read;
134 uint64_t num_write;
135 CRYPTO_EX_DATA ex_data;
136 CRYPTO_RWLOCK *lock;
137};
ea1b02db 138
28a0841b 139#ifndef OPENSSL_NO_SOCK
424d5db2
RL
140# ifdef OPENSSL_SYS_VMS
141typedef unsigned int socklen_t;
142# endif
143
ff234405
MC
144extern CRYPTO_RWLOCK *bio_lookup_lock;
145
28a0841b
RL
146int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa);
147const struct sockaddr *BIO_ADDR_sockaddr(const BIO_ADDR *ap);
148struct sockaddr *BIO_ADDR_sockaddr_noconst(BIO_ADDR *ap);
149socklen_t BIO_ADDR_sockaddr_size(const BIO_ADDR *ap);
150socklen_t BIO_ADDRINFO_sockaddr_size(const BIO_ADDRINFO *bai);
151const struct sockaddr *BIO_ADDRINFO_sockaddr(const BIO_ADDRINFO *bai);
152#endif
153
44cb4f5b
MC
154extern CRYPTO_RWLOCK *bio_type_lock;
155
ff234405
MC
156void bio_sock_cleanup_int(void);
157
b1132792 158#if BIO_FLAGS_UPLINK_INTERNAL==0
ea1b02db 159/* Shortcut UPLINK calls on most platforms... */
0f113f3e
MC
160# define UP_stdin stdin
161# define UP_stdout stdout
162# define UP_stderr stderr
163# define UP_fprintf fprintf
164# define UP_fgets fgets
165# define UP_fread fread
166# define UP_fwrite fwrite
167# undef UP_fsetmod
168# define UP_feof feof
169# define UP_fclose fclose
ea1b02db 170
0f113f3e
MC
171# define UP_fopen fopen
172# define UP_fseek fseek
173# define UP_ftell ftell
174# define UP_fflush fflush
175# define UP_ferror ferror
176# ifdef _WIN32
177# define UP_fileno _fileno
178# define UP_open _open
179# define UP_read _read
180# define UP_write _write
181# define UP_lseek _lseek
182# define UP_close _close
183# else
184# define UP_fileno fileno
185# define UP_open open
186# define UP_read read
187# define UP_write write
188# define UP_lseek lseek
189# define UP_close close
190# endif
28a0841b 191
eed15a83 192#endif
28a0841b 193