Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .azure-pipelines/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
project: build
pipeline: Azure.sonic-buildimage.common_libs
runVersion: 'latestFromBranch'
runBranch: 'refs/heads/master'
runBranch: 'refs/heads/202311'
path: $(Build.ArtifactStagingDirectory)/download
${{ if eq(parameters.arch, 'amd64') }}:
artifact: common-lib
Expand All @@ -77,7 +77,7 @@ jobs:
${{ else }}:
artifact: sonic-swss-common.${{ parameters.arch }}
runVersion: 'latestFromBranch'
runBranch: 'refs/heads/master'
runBranch: 'refs/heads/202405'
displayName: "Download sonic-swss-common"
- script: |
set -ex
Expand Down
13 changes: 12 additions & 1 deletion src/dhcp_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
#define DHCP_OPTIONS_HEADER_SIZE 240
/** Offset of DHCP GIADDR */
#define DHCP_GIADDR_OFFSET 24
/** Offset of magic cookie */
#define MAGIC_COOKIE_OFFSET 236
#define CLIENT_IF_PREFIX "Ethernet"
/** 32-bit decimal of 99.130.83.99 (indicate DHCP packets), Refer to RFC 2131 */
#define DHCP_MAGIC_COOKIE 1669485411

#define OP_LDHA (BPF_LD | BPF_H | BPF_ABS) /** bpf ldh Abs */
#define OP_LDHI (BPF_LD | BPF_H | BPF_IND) /** bpf ldh Ind */
Expand Down Expand Up @@ -288,7 +292,14 @@ static void client_packet_handler(dhcp_device_context_t *context, uint8_t *buffe
ntohs(udp->len) : buffer_sz - UDP_START_OFFSET - sizeof(struct udphdr);
int dhcp_option_sz = dhcp_sz - DHCP_OPTIONS_HEADER_SIZE;
const u_char *dhcp_option = buffer + dhcp_option_offset;

uint32_t magic_cookie = dhcphdr[MAGIC_COOKIE_OFFSET] << 24 | dhcphdr[MAGIC_COOKIE_OFFSET + 1] << 16 |
dhcphdr[MAGIC_COOKIE_OFFSET + 2] << 8 | dhcphdr[MAGIC_COOKIE_OFFSET + 3];
// If magic cookie not equals to DHCP value, its format is not DHCP format, shouldn't count as DHCP packets.
if (magic_cookie != DHCP_MAGIC_COOKIE) {
context->counters[DHCP_COUNTERS_CURRENT][dir][BOOTP_MESSAGE]++;
aggregate_dev.counters[DHCP_COUNTERS_CURRENT][dir][BOOTP_MESSAGE]++;
return;
}
int offset = 0;
while ((offset < (dhcp_option_sz + 1)) && dhcp_option[offset] != 255) {
if (dhcp_option[offset] == OPTION_DHCP_MESSAGE_TYPE) {
Expand Down
1 change: 1 addition & 0 deletions src/dhcp_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef enum
DHCP_MESSAGE_TYPE_NAK = 6,
DHCP_MESSAGE_TYPE_RELEASE = 7,
DHCP_MESSAGE_TYPE_INFORM = 8,
BOOTP_MESSAGE = 9,

DHCP_MESSAGE_TYPE_COUNT
} dhcp_message_type_t;
Expand Down