1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
3 *******************************************************************************
5 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
6 ** Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
9 *******************************************************************************
10 ******************************************************************************/
15 * This is the appallingly named "mid-level" comms layer.
17 * Its purpose is to take packets from the "real" comms layer,
18 * split them up into packets and pass them to the interested
19 * part of the locking mechanism.
21 * It also takes messages from the locking layer, formats them
22 * into packets and sends them to the comms layer.
25 #include <asm/unaligned.h>
27 #include "dlm_internal.h"
34 * Called from the low-level comms layer to process a buffer of
38 int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)
40 const unsigned char *ptr = buf;
41 const struct dlm_header *hd;
45 while (len >= sizeof(struct dlm_header)) {
46 hd = (struct dlm_header *)ptr;
48 /* no message should be more than this otherwise we
49 * cannot deliver this message to upper layers
51 msglen = get_unaligned_le16(&hd->h_length);
52 if (msglen > DEFAULT_BUFFER_SIZE) {
53 log_print("received invalid length header: %u, will abort message parsing",
58 /* caller will take care that leftover
59 * will be parsed next call with more data
66 if (msglen < sizeof(struct dlm_message)) {
67 log_print("dlm msg too small: %u, will skip this message",
74 if (msglen < sizeof(struct dlm_rcom)) {
75 log_print("dlm rcom msg too small: %u, will skip this message",
82 log_print("unsupported h_cmd received: %u, will skip this message",
87 /* for aligned memory access, we just copy current message
88 * to begin of the buffer which contains already parsed buffer
89 * data and should provide align access for upper layers
90 * because the start address of the buffer has a aligned
91 * address. This memmove can be removed when the upperlayer
92 * is capable of unaligned memory access.
94 memmove(buf, ptr, msglen);
95 dlm_receive_buffer((union dlm_packet *)buf, nodeid);