Skip to content

Commit 0664aa4

Browse files
committed
Reorganize pqcomm.h a bit
Group the PG_PROTOCOL() codes, add a comment to AuthRequest now that the AUTH_REQ codes live in a different header, and make some small adjustments to spacing and comment style for the sake of scannability. Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://postgr.es/m/CAOYmi%2B%3D6zg4oXXOQtifrVao_YKiujTDa3u6bxnU08r0FsSig4g%40mail.gmail.com
1 parent e2ceff1 commit 0664aa4

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/include/libpq/pqcomm.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ typedef struct
4040
} AddrInfo;
4141

4242
/* Configure the UNIX socket location for the well known port. */
43-
4443
#define UNIXSOCK_PATH(path, port, sockdir) \
4544
(AssertMacro(sockdir), \
4645
AssertMacro(*(sockdir) != '\0'), \
@@ -69,6 +68,7 @@ is_unixsock_path(const char *path)
6968
return is_absolute_path(path) || path[0] == '@';
7069
}
7170

71+
7272
/*
7373
* These manipulate the frontend/backend protocol version number.
7474
*
@@ -83,7 +83,6 @@ is_unixsock_path(const char *path)
8383
* A frontend isn't required to support anything other than the current
8484
* version.
8585
*/
86-
8786
#define PG_PROTOCOL_MAJOR(v) ((v) >> 16)
8887
#define PG_PROTOCOL_MINOR(v) ((v) & 0x0000ffff)
8988
#define PG_PROTOCOL_FULL(v) (PG_PROTOCOL_MAJOR(v) * 10000 + PG_PROTOCOL_MINOR(v))
@@ -92,12 +91,29 @@ is_unixsock_path(const char *path)
9291
/*
9392
* The earliest and latest frontend/backend protocol version supported.
9493
*/
95-
9694
#define PG_PROTOCOL_EARLIESTPG_PROTOCOL(3,0)
9795
#define PG_PROTOCOL_LATESTPG_PROTOCOL(3,2)
9896

99-
typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
97+
/*
98+
* Reserved protocol numbers, which have special semantics:
99+
*/
100+
101+
/*
102+
* A client can send a cancel-current-operation request to the postmaster.
103+
* This is uglier than sending it directly to the client's backend, but it
104+
* avoids depending on out-of-band communication facilities.
105+
*/
106+
#define CANCEL_REQUEST_CODEPG_PROTOCOL(1234,5678)
107+
108+
/*
109+
* A client can also start by sending a SSL or GSSAPI negotiation request to
110+
* get a secure channel.
111+
*/
112+
#define NEGOTIATE_SSL_CODEPG_PROTOCOL(1234,5679)
113+
#define NEGOTIATE_GSS_CODEPG_PROTOCOL(1234,5680)
114+
100115

116+
typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
101117
typedef ProtocolVersion MsgType;
102118

103119

@@ -106,7 +122,6 @@ typedef ProtocolVersion MsgType;
106122
*
107123
* The initial length is omitted from the packet layouts appearing below.
108124
*/
109-
110125
typedef uint32 PacketLen;
111126

112127
/*
@@ -118,24 +133,16 @@ typedef uint32 PacketLen;
118133
#define MAX_STARTUP_PACKET_LENGTH 10000
119134

120135

121-
typedef uint32 AuthRequest;
136+
typedef uint32 AuthRequest;/* an AUTH_REQ_* code */
122137

123138

124139
/*
125-
* A client can also send a cancel-current-operation request to the postmaster.
126-
* This is uglier than sending it directly to the client's backend, but it
127-
* avoids depending on out-of-band communication facilities.
128-
*
129-
* The cancel request code must not match any protocol version number
130-
* we're ever likely to use. This random choice should do.
140+
* The packet used with a CANCEL_REQUEST_CODE.
131141
*
132142
* Before PostgreSQL v18 and the protocol version bump from 3.0 to 3.2, the
133143
* cancel key was always 4 bytes. With protocol version 3.2, it's variable
134144
* length.
135145
*/
136-
137-
#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
138-
139146
typedef struct CancelRequestPacket
140147
{
141148
/* Note that each field is stored in network byte order! */
@@ -145,7 +152,9 @@ typedef struct CancelRequestPacket
145152
* authorize cancel */
146153
} CancelRequestPacket;
147154

148-
/* Application-Layer Protocol Negotiation is required for direct connections
155+
156+
/*
157+
* Application-Layer Protocol Negotiation is required for direct connections
149158
* to avoid protocol confusion attacks (e.g https://alpaca-attack.com/).
150159
*
151160
* ALPN is specified in RFC 7301
@@ -165,11 +174,4 @@ typedef struct CancelRequestPacket
165174
#define PG_ALPN_PROTOCOL "postgresql"
166175
#define PG_ALPN_PROTOCOL_VECTOR { 10, 'p','o','s','t','g','r','e','s','q','l' }
167176

168-
/*
169-
* A client can also start by sending a SSL or GSSAPI negotiation request to
170-
* get a secure channel.
171-
*/
172-
#define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
173-
#define NEGOTIATE_GSS_CODE PG_PROTOCOL(1234,5680)
174-
175177
#endif/* PQCOMM_H */

0 commit comments

Comments
 (0)