Browse Source

[dhcp] Send user class in DHCP requests

tags/v0.9.7
Michael Brown 15 years ago
parent
commit
4502c04360
3 changed files with 29 additions and 3 deletions
  1. 3
    0
      src/include/gpxe/dhcp.h
  2. 1
    1
      src/include/gpxe/settings.h
  3. 25
    2
      src/net/udp/dhcp.c

+ 3
- 0
src/include/gpxe/dhcp.h View File

@@ -203,6 +203,9 @@ struct dhcp_client_id {
203 203
  */
204 204
 #define DHCP_BOOTFILE_NAME 67
205 205
 
206
+/** User class identifier */
207
+#define DHCP_USER_CLASS_ID 77
208
+
206 209
 /** Client system architecture */
207 210
 #define DHCP_CLIENT_ARCHITECTURE 93
208 211
 

+ 1
- 1
src/include/gpxe/settings.h View File

@@ -225,10 +225,10 @@ extern struct setting root_path_setting __setting;
225 225
 extern struct setting username_setting __setting;
226 226
 extern struct setting password_setting __setting;
227 227
 extern struct setting priority_setting __setting;
228
-extern struct setting bios_drive_setting __setting;
229 228
 extern struct setting uuid_setting __setting;
230 229
 extern struct setting next_server_setting __setting;
231 230
 extern struct setting mac_setting __setting;
231
+extern struct setting user_class_setting __setting;
232 232
 
233 233
 /**
234 234
  * Initialise a settings block

+ 25
- 2
src/net/udp/dhcp.c View File

@@ -101,6 +101,14 @@ struct setting dhcp_server_setting __setting = {
101 101
 	.type = &setting_type_ipv4,
102 102
 };
103 103
 
104
+/** DHCP user class setting */
105
+struct setting user_class_setting __setting = {
106
+	.name = "user-class",
107
+	.description = "User class identifier",
108
+	.tag = DHCP_USER_CLASS_ID,
109
+	.type = &setting_type_string,
110
+};
111
+
104 112
 /**
105 113
  * Name a DHCP packet type
106 114
  *
@@ -834,6 +842,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
834 842
 	struct dhcp_client_uuid client_uuid;
835 843
 	size_t dhcp_features_len;
836 844
 	size_t ll_addr_len;
845
+	ssize_t len;
837 846
 	int rc;
838 847
 
839 848
 	/* Create DHCP packet */
@@ -885,8 +894,8 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
885 894
 
886 895
 	/* Add client UUID, if we have one.  Required for PXE. */
887 896
 	client_uuid.type = DHCP_CLIENT_UUID_TYPE;
888
-	if ( ( rc = fetch_uuid_setting ( NULL, &uuid_setting,
889
-					 &client_uuid.uuid ) ) >= 0 ) {
897
+	if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
898
+					  &client_uuid.uuid ) ) >= 0 ) {
890 899
 		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
891 900
 					    &client_uuid,
892 901
 					    sizeof ( client_uuid ) ) ) != 0 ) {
@@ -896,6 +905,20 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
896 905
 		}
897 906
 	}
898 907
 
908
+	/* Add user class, if we have one. */
909
+	if ( ( len = fetch_setting_len ( NULL, &user_class_setting ) ) >= 0 ) {
910
+		char user_class[len];
911
+		fetch_setting ( NULL, &user_class_setting, user_class,
912
+				sizeof ( user_class ) );
913
+		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_USER_CLASS_ID,
914
+					    &user_class,
915
+					    sizeof ( user_class ) ) ) != 0 ) {
916
+			DBG ( "DHCP could not set user class: %s\n",
917
+			      strerror ( rc ) );
918
+			return rc;
919
+		}
920
+	}
921
+
899 922
 	return 0;
900 923
 }
901 924
 

Loading…
Cancel
Save