Przeglądaj źródła

[dhcp] Remove obsolete dhcp_chaddr() function

As of commit 03f0c23 ("[ipoib] Expose Ethernet-compatible eIPoIB
link-layer addresses and headers"), all link layers have used
addresses which fit within the DHCP chaddr field.  The dhcp_chaddr()
function was therefore made obsolete by this commit, but was
accidentally left present (though unused) in the source code.

Remove the dhcp_chaddr() function and the only remaining use of it,
unnecessarily introduced in commit 08bcc0f ("[dhcp] Check for matching
chaddr in received DHCP packets").

Reported-by: Wissam Shoukair <wissams@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 lat temu
rodzic
commit
6a22170085
1 zmienionych plików z 5 dodań i 75 usunięć
  1. 5
    75
      src/net/udp/dhcp.c

+ 5
- 75
src/net/udp/dhcp.c Wyświetl plik

@@ -130,29 +130,6 @@ static inline const char * dhcp_msgtype_name ( unsigned int msgtype ) {
130 130
 	}
131 131
 }
132 132
 
133
-/**
134
- * Transcribe DHCP client hardware address (for debugging)
135
- *
136
- * @v chaddr		Client hardware address
137
- * @v hlen		Client hardware address length
138
- */
139
-static const char * dhcp_chaddr_ntoa ( const void *chaddr, size_t hlen ) {
140
-	static char buf[ 48 /* 16 x ( "xx" + ":" or NUL ) */ ];
141
-	const uint8_t *chaddr_bytes = chaddr;
142
-	char *tmp = buf;
143
-
144
-	/* Sanity check */
145
-	assert ( hlen < ( sizeof ( buf ) / 3 ) );
146
-
147
-	/* Transcribe address */
148
-	while ( hlen-- ) {
149
-		tmp += sprintf ( tmp, "%s%02x", ( ( tmp == buf ) ? "" : ":" ),
150
-				 *(chaddr_bytes++) );
151
-	}
152
-
153
-	return buf;
154
-}
155
-
156 133
 /****************************************************************************
157 134
  *
158 135
  * DHCP session
@@ -864,53 +841,6 @@ static struct dhcp_session_state dhcp_state_pxebs = {
864 841
  *
865 842
  */
866 843
 
867
-/**
868
- * Construct DHCP client hardware address field and broadcast flag
869
- *
870
- * @v netdev		Network device
871
- * @v chaddr		Hardware address buffer
872
- * @v flags		Flags to set (or NULL)
873
- * @ret hlen		Hardware address length
874
- */
875
-unsigned int dhcp_chaddr ( struct net_device *netdev, void *chaddr,
876
-			   uint16_t *flags ) {
877
-	struct ll_protocol *ll_protocol = netdev->ll_protocol;
878
-	struct dhcphdr *dhcphdr;
879
-	int rc;
880
-
881
-	/* If the link-layer address cannot fit into the chaddr field
882
-	 * (as is the case for IPoIB) then try using the Ethernet-
883
-	 * compatible link-layer address.  If we do this, set the
884
-	 * broadcast flag, since chaddr then does not represent a
885
-	 * valid link-layer address for the return path.
886
-	 *
887
-	 * If we cannot produce an Ethernet-compatible link-layer
888
-	 * address, try using the hardware address.
889
-	 *
890
-	 * If even the hardware address is too large, use an empty
891
-	 * chaddr field and set the broadcast flag.
892
-	 *
893
-	 * This goes against RFC4390, but RFC4390 mandates that we use
894
-	 * a DHCP client identifier that conforms with RFC4361, which
895
-	 * we cannot do without either persistent (NIC-independent)
896
-	 * storage, or by eliminating the hardware address completely
897
-	 * from the DHCP packet, which seems unfriendly to users.
898
-	 */
899
-	if ( ll_protocol->ll_addr_len <= sizeof ( dhcphdr->chaddr ) ) {
900
-		memcpy ( chaddr, netdev->ll_addr, ll_protocol->ll_addr_len );
901
-		return ll_protocol->ll_addr_len;
902
-	}
903
-	if ( flags )
904
-		*flags |= htons ( BOOTP_FL_BROADCAST );
905
-	if ( ( rc = ll_protocol->eth_addr ( netdev->ll_addr, chaddr ) ) == 0 )
906
-		return ETH_ALEN;
907
-	if ( ll_protocol->hw_addr_len <= sizeof ( dhcphdr->chaddr ) ) {
908
-		memcpy ( chaddr, netdev->hw_addr, ll_protocol->hw_addr_len );
909
-		return ll_protocol->hw_addr_len;
910
-	}
911
-	return 0;
912
-}
913
-
914 844
 /**
915 845
  * Create a DHCP packet
916 846
  *
@@ -1176,14 +1106,14 @@ static int dhcp_tx ( struct dhcp_session *dhcp ) {
1176 1106
 static int dhcp_deliver ( struct dhcp_session *dhcp,
1177 1107
 			  struct io_buffer *iobuf,
1178 1108
 			  struct xfer_metadata *meta ) {
1109
+	struct net_device *netdev = dhcp->netdev;
1110
+	struct ll_protocol *ll_protocol = netdev->ll_protocol;
1179 1111
 	struct sockaddr_in *peer;
1180 1112
 	size_t data_len;
1181 1113
 	struct dhcp_packet *dhcppkt;
1182 1114
 	struct dhcphdr *dhcphdr;
1183 1115
 	uint8_t msgtype = 0;
1184 1116
 	struct in_addr server_id = { 0 };
1185
-	uint8_t chaddr[ sizeof ( dhcphdr->chaddr ) ];
1186
-	unsigned int hlen;
1187 1117
 	int rc = 0;
1188 1118
 
1189 1119
 	/* Sanity checks */
@@ -1229,12 +1159,12 @@ static int dhcp_deliver ( struct dhcp_session *dhcp,
1229 1159
 	};
1230 1160
 
1231 1161
 	/* Check for matching client hardware address */
1232
-	hlen = dhcp_chaddr ( dhcp->netdev, chaddr, NULL );
1233
-	if ( memcmp ( dhcphdr->chaddr, chaddr, hlen ) != 0 ) {
1162
+	if ( memcmp ( dhcphdr->chaddr, netdev->ll_addr,
1163
+		      ll_protocol->ll_addr_len ) != 0 ) {
1234 1164
 		DBGC ( dhcp, "DHCP %p %s from %s:%d has bad chaddr %s\n",
1235 1165
 		       dhcp, dhcp_msgtype_name ( msgtype ),
1236 1166
 		       inet_ntoa ( peer->sin_addr ), ntohs ( peer->sin_port ),
1237
-		       dhcp_chaddr_ntoa ( dhcphdr->chaddr, hlen ) );
1167
+		       ll_protocol->ntoa ( dhcphdr->chaddr ) );
1238 1168
 		rc = -EINVAL;
1239 1169
 		goto err_chaddr;
1240 1170
 	}

Ładowanie…
Anuluj
Zapisz