Skip to content

Commit e99589d

Browse files
committed
Feat add IPv6 configuration options, show IPv6 address in interface
1 parent 748596f commit e99589d

File tree

5 files changed

+159
-3
lines changed

5 files changed

+159
-3
lines changed

src/components/PeerUpdate.tsx

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ const PeerUpdate = (props: any) => {
354354
const noUpdateToLoginExpiration = (): Boolean => {
355355
return formPeer.login_expiration_enabled === peer.login_expiration_enabled;
356356
};
357+
const noUpdateToIPv6Enabled = (): Boolean => {
358+
return formPeer.ipv6_enabled === peer.ipv6_enabled;
359+
};
357360
const onChange = (data: any) => {
358361
setFormPeer({ ...formPeer, ...data });
359362
};
@@ -399,6 +402,7 @@ const PeerUpdate = (props: any) => {
399402
ssh_enabled: formPeer.ssh_enabled,
400403
name: formPeer.name,
401404
login_expiration_enabled: formPeer.login_expiration_enabled,
405+
ipv6_enabled: formPeer.ipv6_enabled
402406
} as Peer;
403407
};
404408

@@ -491,7 +495,7 @@ const PeerUpdate = (props: any) => {
491495
.validateFields()
492496
.then((values) => {
493497
setSubmitRunning(true);
494-
if (!noUpdateToName() || !noUpdateToLoginExpiration()) {
498+
if (!noUpdateToName() || !noUpdateToLoginExpiration() || !noUpdateToIPv6Enabled()) {
495499
const peerUpdate = createPeerToSave();
496500
setCallingPeerAPI(true);
497501
dispatch(
@@ -590,6 +594,9 @@ const PeerUpdate = (props: any) => {
590594
const onLoginExpirationChange = (checked: boolean) => {
591595
setFormPeer({ ...formPeer, login_expiration_enabled: checked });
592596
};
597+
const onIPv6EnabledChange = (checked: boolean) => {
598+
setFormPeer({ ...formPeer, ipv6_enabled: checked });
599+
};
593600

594601
const onClickAddNewRoute = () => {
595602
dispatch(routeActions.setSetupNewRouteVisible(true));
@@ -962,6 +969,46 @@ const PeerUpdate = (props: any) => {
962969
</Form.Item>
963970
</Col>
964971
)}
972+
{!isGroupUpdateView && (
973+
<Col span={24}>
974+
<Form.Item
975+
name="ipv6_enabled"
976+
style={{ fontWeight: "500" }}
977+
>
978+
<div
979+
style={{
980+
display: "flex",
981+
gap: "15px",
982+
margin: "25px 0",
983+
lineHeight: "16px",
984+
}}
985+
>
986+
<Tooltip title="IPv6 is currently not supported on all platforms, see System Info for the support status of this peer.">
987+
<Switch
988+
checked={formPeer.ipv6_enabled}
989+
onChange={onIPv6EnabledChange}
990+
disabled={!formPeer.ipv6_supported}
991+
size="small"
992+
/>
993+
</Tooltip>
994+
<div>
995+
<span className="font-500">IPv6 Enabled</span>
996+
<Paragraph
997+
type={"secondary"}
998+
style={{
999+
textAlign: "left",
1000+
whiteSpace: "pre-line",
1001+
fontWeight: "400",
1002+
margin: "0",
1003+
}}
1004+
>
1005+
Whether to enable IPv6 support for this peer.
1006+
</Paragraph>
1007+
</div>
1008+
</div>
1009+
</Form.Item>
1010+
</Col>
1011+
)}
9651012
<Col md={24} lg={isGroupUpdateView ? 24 : 8}>
9661013
<Paragraph
9671014
style={{
@@ -1016,7 +1063,8 @@ const PeerUpdate = (props: any) => {
10161063
updatedPeers.loading ||
10171064
(noUpdateToGroups() &&
10181065
noUpdateToName() &&
1019-
noUpdateToLoginExpiration())
1066+
noUpdateToLoginExpiration() &&
1067+
noUpdateToIPv6Enabled())
10201068
}
10211069
onClick={handleFormSubmit}
10221070
>
@@ -1274,6 +1322,27 @@ const PeerUpdate = (props: any) => {
12741322
</Text>
12751323
</Col>
12761324
)}
1325+
{formPeer.ipv6_supported !== null && (
1326+
<Col
1327+
span={24}
1328+
style={{
1329+
marginBottom: "2px",
1330+
}}
1331+
>
1332+
<Text
1333+
style={{
1334+
width: "100%",
1335+
maxWidth: "130px",
1336+
display: "inline-block",
1337+
}}
1338+
>
1339+
IPv6 Supported:
1340+
</Text>
1341+
<Text type={"secondary"}>
1342+
{formPeer.ipv6_supported ? "yes" : "no"}
1343+
</Text>
1344+
</Col>
1345+
)}
12771346
</Row>
12781347
</Panel>
12791348
</Collapse>

src/store/account/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface Account {
1212
extra: {
1313
peer_approval_enabled: boolean;
1414
}
15+
assign_ipv6_by_default: boolean;
1516
};
1617
}
1718

@@ -23,4 +24,5 @@ export interface FormAccount extends Account {
2324
jwt_allow_groups: string[];
2425
peer_login_expiration_formatted: ExpiresInValue;
2526
peer_approval_enabled: boolean;
26-
}
27+
assign_ipv6_by_default: boolean;
28+
}

src/store/peer/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface Peer {
44
id?: string,
55
name: string,
66
ip: string,
7+
ip6?: string,
78
connected: boolean,
89
last_seen: string,
910
os: string,
@@ -17,6 +18,8 @@ export interface Peer {
1718
last_login: string,
1819
login_expired: boolean,
1920
login_expiration_enabled: boolean,
21+
ipv6_supported: boolean,
22+
ipv6_enabled: boolean,
2023
approval_required: boolean
2124
}
2225

src/views/Peers.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,19 @@ export const Peers = () => {
613613
styleNotification={{}}
614614
/>
615615
</Row>
616+
617+
{ peer.ip6 &&
618+
<Row>
619+
<ButtonCopyMessage
620+
keyMessage={peer.ip6}
621+
toCopy={peer.ip6}
622+
body={<Text type="secondary">{peer.ip6}</Text>}
623+
messageText={"Peer IPv6 copied"}
624+
style={{ marginTop: "-10px" }}
625+
styleNotification={{}}
626+
/>
627+
</Row>
628+
}
616629
</span>
617630
);
618631

src/views/Settings.tsx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ export const Settings = () => {
138138
useState(true);
139139
const [formPeerApprovalEnabled, setFormPeerApprovalEnabled] =
140140
useState(false);
141+
142+
const [assignIPv6ByDefault, setAssignIPv6ByDefault] =
143+
useState(true);
141144
const [jwtGroupsEnabled, setJwtGroupsEnabled] = useState(true);
142145
const [groupsPropagationEnabled, setGroupsPropagationEnabled] =
143146
useState(true);
@@ -261,11 +264,13 @@ export const Settings = () => {
261264
jwt_allow_groups: account.settings.jwt_allow_groups? account.settings.jwt_allow_groups : [],
262265
groups_propagation_enabled: account.settings.groups_propagation_enabled,
263266
peer_approval_enabled: account.settings.extra ? account.settings.extra.peer_approval_enabled : false,
267+
assign_ipv6_by_default: account.settings.assign_ipv6_by_default
264268
} as FormAccount;
265269
setFormAccount(fAccount);
266270
setFormPeerExpirationEnabled(fAccount.peer_login_expiration_enabled);
267271
setFormPeerApprovalEnabled(fAccount.peer_approval_enabled);
268272
setJwtGroupsEnabled(fAccount.jwt_groups_enabled);
273+
setAssignIPv6ByDefault(fAccount.assign_ipv6_by_default);
269274
setGroupsPropagationEnabled(fAccount.groups_propagation_enabled);
270275
setJwtGroupsClaimName(fAccount.jwt_groups_claim_name);
271276
setJwtAllowGroups(fAccount.jwt_allow_groups);
@@ -438,6 +443,8 @@ export const Settings = () => {
438443
groups_propagation_enabled:
439444
updatedAccount.data.settings.groups_propagation_enabled,
440445
peer_approval_enabled: updatedAccount.data.settings.extra? updatedAccount.data.settings.extra.peer_approval_enabled : false,
446+
assign_ipv6_by_default:
447+
updatedAccount.data.settings.assign_ipv6_by_default,
441448
} as FormAccount;
442449
setFormAccount(fAccount);
443450
} else if (updatedAccount.error) {
@@ -474,6 +481,7 @@ export const Settings = () => {
474481
jwt_allow_groups: jwtAllowGroups,
475482
groups_propagation_enabled: groupsPropagationEnabled,
476483
peer_approval_enabled: formPeerApprovalEnabled,
484+
assign_ipv6_by_default: assignIPv6ByDefault
477485
});
478486
})
479487
.catch((errorInfo) => {
@@ -503,6 +511,7 @@ export const Settings = () => {
503511
jwt_groups_claim_name: jwtGroupsClaimName,
504512
jwt_allow_groups: jwtAllowGroups,
505513
groups_propagation_enabled: groupsPropagationEnabled,
514+
assign_ipv6_by_default: values.assign_ipv6_by_default
506515
},
507516
} as Account;
508517
if (isNetBirdHosted() || isLocalDev()) {
@@ -1064,6 +1073,66 @@ export const Settings = () => {
10641073
</Form.Item>
10651074
</Col>
10661075
</Row>
1076+
<Row>
1077+
<Col span={12}>
1078+
<Form.Item name="assign_ipv6_by_default" label="">
1079+
<div
1080+
style={{
1081+
display: "flex",
1082+
gap: "15px",
1083+
}}
1084+
>
1085+
<Switch
1086+
onChange={(checked) => {
1087+
setAssignIPv6ByDefault(checked);
1088+
}}
1089+
size="small"
1090+
checked={assignIPv6ByDefault}
1091+
/>
1092+
<div>
1093+
<label
1094+
style={{
1095+
color: "rgba(0, 0, 0, 0.88)",
1096+
fontSize: "14px",
1097+
fontWeight: "500",
1098+
}}
1099+
>
1100+
Assign IPv6 by default{" "}
1101+
<Tooltip
1102+
title="Determines whether hosts that support it
1103+
automatically get assigned an IPv6 address when
1104+
they are added to the network.
1105+
1106+
Note that this setting does not affect existing
1107+
hosts."
1108+
>
1109+
<Text
1110+
style={{
1111+
marginLeft: "5px",
1112+
fontSize: "14px",
1113+
color: "#bdbdbe",
1114+
}}
1115+
type={"secondary"}
1116+
>
1117+
<QuestionCircleFilled />
1118+
</Text>
1119+
</Tooltip>
1120+
</label>
1121+
<Paragraph
1122+
type={"secondary"}
1123+
style={{
1124+
marginTop: "-2",
1125+
fontWeight: "400",
1126+
marginBottom: "0",
1127+
}}
1128+
>
1129+
Assign an IPv6 address to new hosts that support it by default.
1130+
</Paragraph>
1131+
</div>
1132+
</div>
1133+
</Form.Item>
1134+
</Col>
1135+
</Row>
10671136
<Row>
10681137
<Col span={12}>
10691138
<label

0 commit comments

Comments
 (0)