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"
31 struct dlm_mhandle *dlm_midcomms_get_mhandle(int nodeid, int len,
32 gfp_t allocation, char **ppc)
34 return dlm_lowcomms_get_buffer(nodeid, len, allocation, ppc);
37 void dlm_midcomms_commit_mhandle(struct dlm_mhandle *mh)
39 dlm_lowcomms_commit_buffer(mh);
42 void dlm_midcomms_add_member(int nodeid) { }
44 void dlm_midcomms_remove_member(int nodeid) { }
46 int dlm_midcomms_start(void)
48 return dlm_lowcomms_start();
51 void dlm_midcomms_shutdown(void)
53 dlm_lowcomms_shutdown();
56 int dlm_midcomms_close(int nodeid)
58 return dlm_lowcomms_close(nodeid);
62 * Called from the low-level comms layer to process a buffer of
66 int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)
68 const unsigned char *ptr = buf;
69 const struct dlm_header *hd;
73 while (len >= sizeof(struct dlm_header)) {
74 hd = (struct dlm_header *)ptr;
76 /* no message should be more than DEFAULT_BUFFER_SIZE or
77 * less than dlm_header size.
79 * Some messages does not have a 8 byte length boundary yet
80 * which can occur in a unaligned memory access of some dlm
81 * messages. However this problem need to be fixed at the
82 * sending side, for now it seems nobody run into architecture
83 * related issues yet but it slows down some processing.
84 * Fixing this issue should be scheduled in future by doing
85 * the next major version bump.
87 msglen = le16_to_cpu(hd->h_length);
88 if (msglen > DEFAULT_BUFFER_SIZE ||
89 msglen < sizeof(struct dlm_header)) {
90 log_print("received invalid length header: %u from node %d, will abort message parsing",
95 /* caller will take care that leftover
96 * will be parsed next call with more data
103 if (msglen < sizeof(struct dlm_message)) {
104 log_print("dlm msg too small: %u, will skip this message",
111 if (msglen < sizeof(struct dlm_rcom)) {
112 log_print("dlm rcom msg too small: %u, will skip this message",
119 log_print("unsupported h_cmd received: %u, will skip this message",
124 dlm_receive_buffer((union dlm_packet *)ptr, nodeid);