Skip to content

Commit 7e71de9

Browse files
committed
add udp support
1 parent 5c9fe2f commit 7e71de9

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

api.proto

+10-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ service Listener {
8585
// StatusUpdates opens a stream to listen to connection status updates
8686
// a client has to subscribe and continuously
8787
// listen to the broadcasted updates
88-
rpc StatusUpdates(StatusUpdatesRequest) returns (stream ConnectionStatusUpdate);
88+
rpc StatusUpdates(StatusUpdatesRequest)
89+
returns (stream ConnectionStatusUpdate);
8990
}
9091

9192
message ListenerUpdateRequest {
@@ -211,10 +212,18 @@ message ClientCertFromStore {
211212
optional string subject_filter = 2;
212213
}
213214

215+
enum Protocol {
216+
UNKNOWN = 0;
217+
TCP = 1;
218+
UDP = 2;
219+
}
220+
214221
// Connection
215222
message Connection {
216223
// name is a user friendly connection name that a user may define
217224
optional string name = 1;
225+
// the protocol to use for the connection
226+
optional Protocol protocol = 10;
218227
// remote_addr is a remote pomerium host:port
219228
string remote_addr = 2;
220229
// listen_address, if not provided, will assign a random port each time

src/renderer/pages/ConnectForm.tsx

+34-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ import {
88
CardContent,
99
Chip,
1010
Container,
11+
FormControl,
1112
FormControlLabel,
1213
FormHelperText,
1314
Grid,
1415
IconButton,
16+
InputLabel,
17+
MenuItem,
18+
Select,
19+
SelectChangeEvent,
1520
styled,
1621
Switch,
1722
Typography,
@@ -38,6 +43,7 @@ import { formatTag } from '../../shared/validators';
3843
import {
3944
ClientCertFromStore,
4045
Connection,
46+
Protocol,
4147
Record,
4248
Selector,
4349
} from '../../shared/pb/api';
@@ -115,6 +121,7 @@ interface Props {
115121

116122
const initialConnData: Connection = {
117123
name: undefined,
124+
protocol: Protocol.TCP,
118125
remoteAddr: '',
119126
listenAddr: undefined,
120127
pomeriumUrl: undefined,
@@ -239,7 +246,7 @@ const ConnectForm: FC<Props> = () => {
239246
useState(false);
240247

241248
const saveClientCertFromStore = (
242-
value: ClientCertFromStore | undefined,
249+
value: ClientCertFromStore | undefined
243250
): void => {
244251
setConnection({
245252
...connection,
@@ -265,7 +272,7 @@ const ConnectForm: FC<Props> = () => {
265272
};
266273

267274
const clientCertFiltersSummary = getClientCertFiltersSummary(
268-
connection?.clientCertFromStore,
275+
connection?.clientCertFromStore
269276
);
270277

271278
const saveCertText = (value: string): void => {
@@ -310,6 +317,14 @@ const ConnectForm: FC<Props> = () => {
310317
setShowCertInput(true);
311318
};
312319

320+
const handleChangeProtocol = (evt: SelectChangeEvent) => {
321+
setConnection((oldConnection) => {
322+
oldConnection.protocol =
323+
evt.target.value === 'UDP' ? Protocol.UDP : Protocol.TCP;
324+
return oldConnection;
325+
});
326+
};
327+
313328
const saveConnection = (): void => {
314329
const record = {
315330
tags,
@@ -552,6 +567,23 @@ const ConnectForm: FC<Props> = () => {
552567
helperText="Name of the route."
553568
/>
554569
</Grid>
570+
<Grid item xs={12}>
571+
<FormControl fullWidth>
572+
<InputLabel id="protocol-label">Protocol</InputLabel>
573+
<Select
574+
labelId="protocol-label"
575+
id="demo-simple-select"
576+
value={
577+
connection?.protocol === Protocol.UDP ? 'UDP' : 'TCP'
578+
}
579+
label="Age"
580+
onChange={handleChangeProtocol}
581+
>
582+
<MenuItem value="TCP">TCP</MenuItem>
583+
<MenuItem value="UDP">UDP</MenuItem>
584+
</Select>
585+
</FormControl>
586+
</Grid>
555587
<Grid item xs={12}>
556588
<TextField
557589
fullWidth

src/shared/pb/api.ts

+57
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,45 @@ import * as _m0 from 'protobufjs/minimal';
1919

2020
export const protobufPackage = 'pomerium.cli';
2121

22+
export enum Protocol {
23+
UNKNOWN = 0,
24+
TCP = 1,
25+
UDP = 2,
26+
UNRECOGNIZED = -1,
27+
}
28+
29+
export function protocolFromJSON(object: any): Protocol {
30+
switch (object) {
31+
case 0:
32+
case 'UNKNOWN':
33+
return Protocol.UNKNOWN;
34+
case 1:
35+
case 'TCP':
36+
return Protocol.TCP;
37+
case 2:
38+
case 'UDP':
39+
return Protocol.UDP;
40+
case -1:
41+
case 'UNRECOGNIZED':
42+
default:
43+
return Protocol.UNRECOGNIZED;
44+
}
45+
}
46+
47+
export function protocolToJSON(object: Protocol): string {
48+
switch (object) {
49+
case Protocol.UNKNOWN:
50+
return 'UNKNOWN';
51+
case Protocol.TCP:
52+
return 'TCP';
53+
case Protocol.UDP:
54+
return 'UDP';
55+
case Protocol.UNRECOGNIZED:
56+
default:
57+
return 'UNRECOGNIZED';
58+
}
59+
}
60+
2261
/** Record represents a single tunnel record in the configuration */
2362
export interface Record {
2463
/** if omitted, a new record would be created */
@@ -322,6 +361,8 @@ export interface ClientCertFromStore {
322361
export interface Connection {
323362
/** name is a user friendly connection name that a user may define */
324363
name?: string | undefined;
364+
/** the protocol to use for the connection */
365+
protocol?: Protocol | undefined;
325366
/** remote_addr is a remote pomerium host:port */
326367
remoteAddr: string;
327368
/** listen_address, if not provided, will assign a random port each time */
@@ -2332,6 +2373,7 @@ export const ClientCertFromStore = {
23322373
function createBaseConnection(): Connection {
23332374
return {
23342375
name: undefined,
2376+
protocol: undefined,
23352377
remoteAddr: '',
23362378
listenAddr: undefined,
23372379
pomeriumUrl: undefined,
@@ -2350,6 +2392,9 @@ export const Connection = {
23502392
if (message.name !== undefined) {
23512393
writer.uint32(10).string(message.name);
23522394
}
2395+
if (message.protocol !== undefined) {
2396+
writer.uint32(80).int32(message.protocol);
2397+
}
23532398
if (message.remoteAddr !== '') {
23542399
writer.uint32(18).string(message.remoteAddr);
23552400
}
@@ -2387,6 +2432,9 @@ export const Connection = {
23872432
case 1:
23882433
message.name = reader.string();
23892434
break;
2435+
case 10:
2436+
message.protocol = reader.int32() as any;
2437+
break;
23902438
case 2:
23912439
message.remoteAddr = reader.string();
23922440
break;
@@ -2422,6 +2470,9 @@ export const Connection = {
24222470
fromJSON(object: any): Connection {
24232471
return {
24242472
name: isSet(object.name) ? String(object.name) : undefined,
2473+
protocol: isSet(object.protocol)
2474+
? protocolFromJSON(object.protocol)
2475+
: undefined,
24252476
remoteAddr: isSet(object.remoteAddr) ? String(object.remoteAddr) : '',
24262477
listenAddr: isSet(object.listenAddr)
24272478
? String(object.listenAddr)
@@ -2445,6 +2496,11 @@ export const Connection = {
24452496
toJSON(message: Connection): unknown {
24462497
const obj: any = {};
24472498
message.name !== undefined && (obj.name = message.name);
2499+
message.protocol !== undefined &&
2500+
(obj.protocol =
2501+
message.protocol !== undefined
2502+
? protocolToJSON(message.protocol)
2503+
: undefined);
24482504
message.remoteAddr !== undefined && (obj.remoteAddr = message.remoteAddr);
24492505
message.listenAddr !== undefined && (obj.listenAddr = message.listenAddr);
24502506
message.pomeriumUrl !== undefined &&
@@ -2472,6 +2528,7 @@ export const Connection = {
24722528
): Connection {
24732529
const message = createBaseConnection();
24742530
message.name = object.name ?? undefined;
2531+
message.protocol = object.protocol ?? undefined;
24752532
message.remoteAddr = object.remoteAddr ?? '';
24762533
message.listenAddr = object.listenAddr ?? undefined;
24772534
message.pomeriumUrl = object.pomeriumUrl ?? undefined;

0 commit comments

Comments
 (0)