@@ -33,7 +33,7 @@ use embassy_net_driver::{Driver, LinkState};
33
33
use embassy_sync:: waitqueue:: WakerRegistration ;
34
34
use embassy_time:: { Instant , Timer } ;
35
35
#[ allow( unused_imports) ]
36
- use heapless:: Vec ;
36
+ use heapless:: { String , Vec } ;
37
37
#[ cfg( feature = "dns" ) ]
38
38
pub use smoltcp:: config:: DNS_MAX_SERVER_COUNT ;
39
39
#[ cfg( feature = "igmp" ) ]
@@ -66,6 +66,8 @@ const LOCAL_PORT_MAX: u16 = 65535;
66
66
const MAX_QUERIES : usize = 4 ;
67
67
#[ cfg( feature = "dhcpv4-hostname" ) ]
68
68
const MAX_HOSTNAME_LEN : usize = 32 ;
69
+ #[ cfg( all( feature = "dhcpv4-domainname" , feature = "dns" ) ) ]
70
+ const MAX_DNS_QUERY_LEN : usize = 128 ;
69
71
70
72
/// Memory resources needed for a network stack.
71
73
pub struct StackResources < const SOCK : usize > {
@@ -110,6 +112,9 @@ pub struct StaticConfigV4 {
110
112
pub gateway : Option < Ipv4Address > ,
111
113
/// DNS servers.
112
114
pub dns_servers : Vec < Ipv4Address , 3 > ,
115
+ /// Domain name.
116
+ #[ cfg( feature = "dhcpv4-domainname" ) ]
117
+ pub domain_name : Option < String < { smoltcp:: config:: DHCP_MAX_DOMAIN_NAME_SIZE } > > ,
113
118
}
114
119
115
120
/// Static IPv6 address configuration
@@ -146,7 +151,7 @@ pub struct DhcpConfig {
146
151
pub client_port : u16 ,
147
152
/// Our hostname. This will be sent to the DHCP server as Option 12.
148
153
#[ cfg( feature = "dhcpv4-hostname" ) ]
149
- pub hostname : Option < heapless :: String < MAX_HOSTNAME_LEN > > ,
154
+ pub hostname : Option < String < MAX_HOSTNAME_LEN > > ,
150
155
}
151
156
152
157
#[ cfg( feature = "dhcpv4" ) ]
@@ -527,6 +532,22 @@ impl<D: Driver> Stack<D> {
527
532
_ => { }
528
533
}
529
534
535
+ // Form name together with domain name.
536
+ #[ cfg( feature = "dhcpv4-domainname" ) ]
537
+ let name = & {
538
+ use core:: str:: FromStr ;
539
+
540
+ let mut name = String :: < MAX_DNS_QUERY_LEN > :: from_str ( name) . map_err ( |_| dns:: Error :: NameTooLong ) ?;
541
+
542
+ if let Some ( Some ( domain_name) ) = & self . inner . borrow ( ) . static_v4 . as_ref ( ) . map ( |c| & c. domain_name ) {
543
+ if !domain_name. is_empty ( ) {
544
+ name. push ( '.' ) . map_err ( |_| dns:: Error :: NameTooLong ) ?;
545
+ name. push_str ( & domain_name) . map_err ( |_| dns:: Error :: NameTooLong ) ?;
546
+ }
547
+ }
548
+ name
549
+ } ;
550
+
530
551
let query = poll_fn ( |cx| {
531
552
self . with_mut ( |s, i| {
532
553
let socket = s. sockets . get_mut :: < dns:: Socket > ( i. dns_socket ) ;
@@ -902,6 +923,8 @@ impl<D: Driver> Inner<D> {
902
923
address : config. address ,
903
924
gateway : config. router ,
904
925
dns_servers : config. dns_servers ,
926
+ #[ cfg( feature = "dhcpv4-domainname" ) ]
927
+ domain_name : config. domain_name ,
905
928
} ) ;
906
929
apply_config = true ;
907
930
}
0 commit comments