Skip to content

Commit

Permalink
Merge pull request #401 from freifunkMUC/feature/new-mtu-client-confi…
Browse files Browse the repository at this point in the history
…guration

Adds a new client configuration item for maximum transmission unit 'MTU' (`clientconfig.mtu`).
  • Loading branch information
nwaldispuehl committed Jul 3, 2023
2 parents 3ecb9d0 + c83abc3 commit f02c257
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions cmd/serve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Register(app *kingpin.Application) *servecmd {
cli.Flag("dns-domain", "A domain to serve configured device names authoritatively").Envar("WG_DNS_DOMAIN").StringVar(&cmd.AppConfig.DNS.Domain)
cli.Flag("clientconfig-dns-servers", "DNS servers (one or more IPs, comma separated) to write into the client configuration file").Envar("WG_CLIENTCONFIG_DNS_SERVERS").StringsVar(&cmd.AppConfig.ClientConfig.DNSServers)
cli.Flag("clientconfig-dns-search-domain", "DNS search domain to write into the client configuration file").Envar("WG_CLIENTCONFIG_DNS_SEARCH_DOMAIN").StringVar(&cmd.AppConfig.ClientConfig.DNSSearchDomain)
cli.Flag("clientconfig-mtu", "The maximum transmission unit (MTU) to write into the client configuration file").Envar("WG_CLIENTCONFIG_MTU").IntVar(&cmd.AppConfig.ClientConfig.MTU)
return cmd
}

Expand Down
4 changes: 3 additions & 1 deletion docs/2-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The format for specifying multiple values for options that allow it is:
Here's what you can configure:

| Environment Variable | CLI Flag | Config File Path | Required | Default (docker) | Description |
| ------------------------------------ | ----------------------------------- | ------------------------------ | -------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|--------------------------------------|-------------------------------------| ------------------------------ | -------- | -------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `WG_CONFIG` | `--config` | | | | The path to a wg-access-server config.yaml file |
| `WG_LOG_LEVEL` | `--log-level` | `logLevel` | | `info` | The global log level |
| `WG_ADMIN_USERNAME` | `--admin-username` | `adminUsername` | | `admin` | The admin account username |
Expand Down Expand Up @@ -56,6 +56,8 @@ Here's what you can configure:
| `WG_DNS_DOMAIN` | `--dns-domain` | `dns.domain` | | | A domain to serve configured devices authoritatively. Queries for names in the format <device>.<user>.<domain> will be answered with the device's IP addresses. |
| `WG_CLIENTCONFIG_DNS_SERVERS` | `--clientconfig-dns-servers` | `clientconfig.dnsservers` | | | DNS servers (one or more IP addresses) to write into the client configuration file. Are used instead of the servers DNS settings, if set. |
| `WG_CLIENTCONFIG_DNS_SEARCH_DOMAIN` | `--clientconfig-dns-search-domain` | `clientconfig.dnssearchdomain` | | | DNS search domain to write into the client configuration file. |
| `WG_CLIENTCONFIG_MTU` | `--clientconfig-mtu` | `clientconfig.mtu` | | | The maximum transmission unit (MTU) to write into the client configuration file. |


## The Config File (config.yaml)

Expand Down
5 changes: 5 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ type AppConfig struct {
// Search domain to be provided with the client configuration file.
// Empty by default.
DNSSearchDomain string `yaml:"dnsSearchDomain"`
// The maximum transmission unit (MTU) to be written into the client configuration file.
// If left empty "the MTU is automatically determined from the endpoint addresses or the system default route,
// which is usually a sane choice." (From wg-quick 8 manual page.)
// Empty by default.
MTU int `yaml:"mtu"`
} `yaml:"clientConfig"`
// Auth configures optional authentication backends
// to control access to the web ui.
Expand Down
1 change: 1 addition & 0 deletions internal/services/server_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (s *ServerService) Info(ctx context.Context, req *proto.InfoReq) (*proto.In
Filename: s.Config.Filename,
ClientConfigDnsServers: clientConfigDnsServers(s.Config),
ClientConfigDnsSearchDomain: s.Config.ClientConfig.DNSSearchDomain,
ClientConfigMtu: int32(s.Config.ClientConfig.MTU),
}, nil
}

Expand Down
29 changes: 20 additions & 9 deletions proto/proto/server.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ message InfoRes {
google.protobuf.Duration inactive_device_grace_period = 12;
string client_config_dns_servers = 13;
string client_config_dns_search_domain = 14;
int32 client_config_mtu = 15;
}
7 changes: 4 additions & 3 deletions website/src/components/AddDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const AddDevice = observer(class AddDevice extends React.Component<Props>
PrivateKey = ${privateKey}
Address = ${device.address}
${ 0 < dnsInfo.length && `DNS = ${ dnsInfo.join(", ") }` }
${ info.clientConfigMtu != 0 && `MTU = ${info.clientConfigMtu}` }
[Peer]
PublicKey = ${info.publicKey}
Expand Down Expand Up @@ -175,15 +176,15 @@ export const AddDevice = observer(class AddDevice extends React.Component<Props>
/>
<FormHelperText id="device-publickey-text">Put your public key to a pre-generated private key here. Replace the private key in the config file after downloading it.</FormHelperText>
</FormControl>
<FormControlLabel
<FormControlLabel
control={
<Checkbox
id="device-presharedkey"
value={this.useDevicePresharekey}
onChange={(event) => (this.useDevicePresharekey = event.currentTarget.checked)}
/>
}
label="Use pre-shared key"
}
label="Use pre-shared key"
/>
</AccordionDetails>
</Accordion>
Expand Down
18 changes: 18 additions & 0 deletions website/src/sdk/server_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export declare namespace InfoRes {
inactiveDeviceGracePeriod?: googleProtobufDuration.Duration.AsObject,
clientConfigDnsServers: string,
clientConfigDnsSearchDomain: string,
clientConfigMtu: number,
}
}

Expand Down Expand Up @@ -237,6 +238,13 @@ export class InfoRes extends jspb.Message {
(jspb.Message as any).setProto3StringField(this, 14, value);
}

getClientConfigMtu(): number {return jspb.Message.getFieldWithDefault(this, 15, 0);
}

setClientConfigMtu(value: number): void {
(jspb.Message as any).setProto3IntField(this, 15, value);
}

serializeBinary(): Uint8Array {
const writer = new jspb.BinaryWriter();
InfoRes.serializeBinaryToWriter(this, writer);
Expand All @@ -260,6 +268,7 @@ export class InfoRes extends jspb.Message {
inactiveDeviceGracePeriod: (f = this.getInactiveDeviceGracePeriod()) && f.toObject(),
clientConfigDnsServers: this.getClientConfigDnsServers(),
clientConfigDnsSearchDomain: this.getClientConfigDnsSearchDomain(),
clientConfigMtu: this.getClientConfigMtu(),
};
}

Expand Down Expand Up @@ -320,6 +329,10 @@ export class InfoRes extends jspb.Message {
if (field14.length > 0) {
writer.writeString(14, field14);
}
const field15 = message.getClientConfigMtu();
if (field15 != 0) {
writer.writeInt32(15, field15);
}
}

static deserializeBinary(bytes: Uint8Array): InfoRes {
Expand Down Expand Up @@ -393,6 +406,10 @@ export class InfoRes extends jspb.Message {
const field14 = reader.readString()
message.setClientConfigDnsSearchDomain(field14);
break;
case 15:
const field15 = reader.readInt32()
message.setClientConfigMtu(field15);
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -431,6 +448,7 @@ function InfoResFromObject(obj: InfoRes.AsObject | undefined): InfoRes | undefin
message.setInactiveDeviceGracePeriod(DurationFromObject(obj.inactiveDeviceGracePeriod));
message.setClientConfigDnsServers(obj.clientConfigDnsServers);
message.setClientConfigDnsSearchDomain(obj.clientConfigDnsSearchDomain);
message.setClientConfigMtu(obj.clientConfigMtu);
return message;
}

Expand Down

0 comments on commit f02c257

Please sign in to comment.