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 "dlm_internal.h"
32 * Called from the low-level comms layer to process a buffer of
36 int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)
38 const unsigned char *ptr = buf;
39 const struct dlm_header *hd;
43 while (len >= sizeof(struct dlm_header)) {
44 hd = (struct dlm_header *)ptr;
46 /* no message should be more than DEFAULT_BUFFER_SIZE or
47 * less than dlm_header size.
49 * Some messages does not have a 8 byte length boundary yet
50 * which can occur in a unaligned memory access of some dlm
51 * messages. However this problem need to be fixed at the
52 * sending side, for now it seems nobody run into architecture
53 * related issues yet but it slows down some processing.
54 * Fixing this issue should be scheduled in future by doing
55 * the next major version bump.
57 msglen = le16_to_cpu(hd->h_length);
58 if (msglen > DEFAULT_BUFFER_SIZE ||
59 msglen < sizeof(struct dlm_header)) {
60 log_print("received invalid length header: %u from node %d, will abort message parsing",
65 /* caller will take care that leftover
66 * will be parsed next call with more data
73 if (msglen < sizeof(struct dlm_message)) {
74 log_print("dlm msg too small: %u, will skip this message",
81 if (msglen < sizeof(struct dlm_rcom)) {
82 log_print("dlm rcom msg too small: %u, will skip this message",
89 log_print("unsupported h_cmd received: %u, will skip this message",
94 dlm_receive_buffer((union dlm_packet *)ptr, nodeid);