@@ -104,6 +104,30 @@ static inline bool parse_fwmark(uint32_t *fwmark, uint32_t *flags, const char *v
104104 return false;
105105}
106106
107+ #ifdef __linux__
108+ static inline bool parse_bind_dev (uint32_t * bind_dev , char * bind_dev_name , uint32_t * flags , const char * value )
109+ {
110+ if (strlen (value ) > IFNAMSIZ ) {
111+ fprintf (stderr , "BindDev must be shorter or equal to %d chars, found: '%s'\n" , IFNAMSIZ , value );
112+ return false;
113+ }
114+
115+ snprintf (bind_dev_name , IFNAMSIZ , "%s" , value );
116+ unsigned int i = if_nametoindex (value );
117+ if (errno ) {
118+ fprintf (stderr , "Failed to get ifIndex for BindDev '%s': %s\n" , value , strerror (errno ));
119+ return false;
120+ }
121+
122+ * flags |= WGDEVICE_HAS_BIND_DEV ;
123+ * bind_dev = (int ) i ;
124+
125+ printf ("bind-dev %s translates to %d\n" , value , i );
126+
127+ return true;
128+ }
129+ #endif
130+
107131static inline bool parse_key (uint8_t key [static WG_KEY_LEN ], const char * value )
108132{
109133 if (!key_from_base64 (key , value )) {
@@ -446,6 +470,10 @@ static bool process_line(struct config_ctx *ctx, const char *line)
446470 ret = parse_port (& ctx -> device -> listen_port , & ctx -> device -> flags , value );
447471 else if (key_match ("FwMark" ))
448472 ret = parse_fwmark (& ctx -> device -> fwmark , & ctx -> device -> flags , value );
473+ #ifdef __linux__
474+ else if (key_match ("BindDev "))
475+ ret = parse_bind_dev (& ctx -> device -> bind_dev , (char * ) & ctx -> device -> bind_dev_name , & ctx -> device -> flags , value );
476+ #endif
449477 else if (key_match ("PrivateKey ")) {
450478 ret = parse_key (ctx -> device -> private_key , value );
451479 if (ret )
@@ -582,6 +610,13 @@ struct wgdevice *config_read_cmd(const char *argv[], int argc)
582610 goto error ;
583611 argv += 2 ;
584612 argc -= 2 ;
613+ #ifdef __linux__
614+ } else if (!strcmp (argv [0 ], "bind-dev" ) && argc >= 2 && !peer ) {
615+ if (!parse_bind_dev (& device -> bind_dev , (char * ) device -> bind_dev_name , & device -> flags , argv [1 ]))
616+ goto error ;
617+ argv += 2 ;
618+ argc -= 2 ;
619+ #endif
585620 } else if (!strcmp (argv [0 ], "private-key" ) && argc >= 2 && !peer ) {
586621 if (!parse_keyfile (device -> private_key , argv [1 ]))
587622 goto error ;
0 commit comments