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