| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | messages.c header
|
|---|
| 4 | Copyright (C) Andrew Tridgell 2000
|
|---|
| 5 | Copyright (C) 2001, 2002 by Martin Pool
|
|---|
| 6 |
|
|---|
| 7 | This program is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 10 | (at your option) any later version.
|
|---|
| 11 |
|
|---|
| 12 | This program is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | GNU General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #ifndef _MESSAGES_H_
|
|---|
| 22 | #define _MESSAGES_H_
|
|---|
| 23 |
|
|---|
| 24 | /* change the message version with any incompatible changes in the protocol */
|
|---|
| 25 | #define MESSAGE_VERSION 2
|
|---|
| 26 |
|
|---|
| 27 | /*
|
|---|
| 28 | * Special flags passed to message_send. Allocated from the top, lets see when
|
|---|
| 29 | * it collides with the message types in the lower 16 bits :-)
|
|---|
| 30 | */
|
|---|
| 31 |
|
|---|
| 32 | /*
|
|---|
| 33 | * Under high load, this message can be dropped. Use for notify-style
|
|---|
| 34 | * messages that are not critical for correct operation.
|
|---|
| 35 | */
|
|---|
| 36 | #define MSG_FLAG_LOWPRIORITY 0x80000000
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | /* Flags to classify messages - used in message_send_all() */
|
|---|
| 40 | /* Sender will filter by flag. */
|
|---|
| 41 |
|
|---|
| 42 | #define FLAG_MSG_GENERAL 0x0001
|
|---|
| 43 | #define FLAG_MSG_SMBD 0x0002
|
|---|
| 44 | #define FLAG_MSG_NMBD 0x0004
|
|---|
| 45 | #define FLAG_MSG_PRINT_NOTIFY 0x0008
|
|---|
| 46 | #define FLAG_MSG_PRINT_GENERAL 0x0010
|
|---|
| 47 | /* dbwrap messages 4001-4999 */
|
|---|
| 48 | #define FLAG_MSG_DBWRAP 0x0020
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | /*
|
|---|
| 52 | * Virtual Node Numbers are identifying a node within a cluster. Ctdbd sets
|
|---|
| 53 | * this, we retrieve our vnn from it.
|
|---|
| 54 | */
|
|---|
| 55 |
|
|---|
| 56 | #define NONCLUSTER_VNN (0xFFFFFFFF)
|
|---|
| 57 |
|
|---|
| 58 | /*
|
|---|
| 59 | * ctdb gives us 64-bit server ids for messaging_send. This is done to avoid
|
|---|
| 60 | * pid clashes and to be able to register for special messages like "all
|
|---|
| 61 | * smbds".
|
|---|
| 62 | *
|
|---|
| 63 | * Normal individual server id's have the upper 32 bits to 0, I picked "1" for
|
|---|
| 64 | * Samba, other subsystems might use something else.
|
|---|
| 65 | */
|
|---|
| 66 |
|
|---|
| 67 | #define MSG_SRVID_SAMBA 0x0000000100000000LL
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | struct server_id {
|
|---|
| 71 | pid_t pid;
|
|---|
| 72 | #ifdef CLUSTER_SUPPORT
|
|---|
| 73 | uint32 vnn;
|
|---|
| 74 | #endif
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | #ifdef CLUSTER_SUPPORT
|
|---|
| 78 | #define MSG_BROADCAST_PID_STR "0:0"
|
|---|
| 79 | #else
|
|---|
| 80 | #define MSG_BROADCAST_PID_STR "0"
|
|---|
| 81 | #endif
|
|---|
| 82 |
|
|---|
| 83 | struct messaging_context;
|
|---|
| 84 | struct messaging_rec;
|
|---|
| 85 |
|
|---|
| 86 | /*
|
|---|
| 87 | * struct messaging_context belongs to messages.c, but because we still have
|
|---|
| 88 | * messaging_dispatch, we need it here. Once we get rid of signals for
|
|---|
| 89 | * notifying processes, this will go.
|
|---|
| 90 | */
|
|---|
| 91 |
|
|---|
| 92 | struct messaging_context {
|
|---|
| 93 | struct server_id id;
|
|---|
| 94 | struct event_context *event_ctx;
|
|---|
| 95 | struct messaging_callback *callbacks;
|
|---|
| 96 |
|
|---|
| 97 | struct messaging_backend *local;
|
|---|
| 98 | struct messaging_backend *remote;
|
|---|
| 99 | };
|
|---|
| 100 |
|
|---|
| 101 | struct messaging_backend {
|
|---|
| 102 | NTSTATUS (*send_fn)(struct messaging_context *msg_ctx,
|
|---|
| 103 | struct server_id pid, int msg_type,
|
|---|
| 104 | const DATA_BLOB *data,
|
|---|
| 105 | struct messaging_backend *backend);
|
|---|
| 106 | void *private_data;
|
|---|
| 107 | };
|
|---|
| 108 |
|
|---|
| 109 | NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx,
|
|---|
| 110 | TALLOC_CTX *mem_ctx,
|
|---|
| 111 | struct messaging_backend **presult);
|
|---|
| 112 |
|
|---|
| 113 | NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
|
|---|
| 114 | TALLOC_CTX *mem_ctx,
|
|---|
| 115 | struct messaging_backend **presult);
|
|---|
| 116 | struct ctdbd_connection *messaging_ctdbd_connection(void);
|
|---|
| 117 |
|
|---|
| 118 | bool message_send_all(struct messaging_context *msg_ctx,
|
|---|
| 119 | int msg_type,
|
|---|
| 120 | const void *buf, size_t len,
|
|---|
| 121 | int *n_sent);
|
|---|
| 122 | struct event_context *messaging_event_context(struct messaging_context *msg_ctx);
|
|---|
| 123 | struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
|
|---|
| 124 | struct server_id server_id,
|
|---|
| 125 | struct event_context *ev);
|
|---|
| 126 |
|
|---|
| 127 | /*
|
|---|
| 128 | * re-init after a fork
|
|---|
| 129 | */
|
|---|
| 130 | NTSTATUS messaging_reinit(struct messaging_context *msg_ctx);
|
|---|
| 131 |
|
|---|
| 132 | NTSTATUS messaging_register(struct messaging_context *msg_ctx,
|
|---|
| 133 | void *private_data,
|
|---|
| 134 | uint32_t msg_type,
|
|---|
| 135 | void (*fn)(struct messaging_context *msg,
|
|---|
| 136 | void *private_data,
|
|---|
| 137 | uint32_t msg_type,
|
|---|
| 138 | struct server_id server_id,
|
|---|
| 139 | DATA_BLOB *data));
|
|---|
| 140 | void messaging_deregister(struct messaging_context *ctx, uint32_t msg_type,
|
|---|
| 141 | void *private_data);
|
|---|
| 142 | NTSTATUS messaging_send(struct messaging_context *msg_ctx,
|
|---|
| 143 | struct server_id server,
|
|---|
| 144 | uint32_t msg_type, const DATA_BLOB *data);
|
|---|
| 145 | NTSTATUS messaging_send_buf(struct messaging_context *msg_ctx,
|
|---|
| 146 | struct server_id server, uint32_t msg_type,
|
|---|
| 147 | const uint8 *buf, size_t len);
|
|---|
| 148 | void messaging_dispatch_rec(struct messaging_context *msg_ctx,
|
|---|
| 149 | struct messaging_rec *rec);
|
|---|
| 150 |
|
|---|
| 151 | #endif
|
|---|