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_WINBIND 0x0008
|
---|
46 | #define FLAG_MSG_PRINT_GENERAL 0x0010
|
---|
47 | /* dbwrap messages 4001-4999 */
|
---|
48 | #define FLAG_MSG_DBWRAP 0x0020
|
---|
49 |
|
---|
50 | /*
|
---|
51 | * ctdb gives us 64-bit server ids for messaging_send. This is done to avoid
|
---|
52 | * pid clashes and to be able to register for special messages like "all
|
---|
53 | * smbds".
|
---|
54 | *
|
---|
55 | * Normal individual server id's have the upper 32 bits to 0, I picked "1" for
|
---|
56 | * Samba, other subsystems might use something else.
|
---|
57 | */
|
---|
58 |
|
---|
59 | #define MSG_SRVID_SAMBA 0x0000000100000000LL
|
---|
60 |
|
---|
61 | #include "librpc/gen_ndr/server_id.h"
|
---|
62 | #include "lib/util/data_blob.h"
|
---|
63 | #include "system/network.h"
|
---|
64 |
|
---|
65 | #define MSG_BROADCAST_PID_STR "0:0"
|
---|
66 |
|
---|
67 | struct messaging_context;
|
---|
68 | struct messaging_rec;
|
---|
69 |
|
---|
70 | struct messaging_backend {
|
---|
71 | int (*send_fn)(struct server_id src,
|
---|
72 | struct server_id pid, int msg_type,
|
---|
73 | const struct iovec *iov, int iovlen,
|
---|
74 | const int *fds, size_t num_fds,
|
---|
75 | struct messaging_backend *backend);
|
---|
76 | void *private_data;
|
---|
77 | };
|
---|
78 |
|
---|
79 | int messaging_ctdbd_init(struct messaging_context *msg_ctx,
|
---|
80 | TALLOC_CTX *mem_ctx,
|
---|
81 | struct messaging_backend **presult);
|
---|
82 | struct ctdbd_connection *messaging_ctdbd_connection(void);
|
---|
83 |
|
---|
84 | bool message_send_all(struct messaging_context *msg_ctx,
|
---|
85 | int msg_type,
|
---|
86 | const void *buf, size_t len,
|
---|
87 | int *n_sent);
|
---|
88 | struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
|
---|
89 | struct tevent_context *ev);
|
---|
90 |
|
---|
91 | struct server_id messaging_server_id(const struct messaging_context *msg_ctx);
|
---|
92 | struct tevent_context *messaging_tevent_context(
|
---|
93 | struct messaging_context *msg_ctx);
|
---|
94 | struct server_id_db *messaging_names_db(struct messaging_context *msg_ctx);
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * re-init after a fork
|
---|
98 | */
|
---|
99 | NTSTATUS messaging_reinit(struct messaging_context *msg_ctx);
|
---|
100 |
|
---|
101 | NTSTATUS messaging_register(struct messaging_context *msg_ctx,
|
---|
102 | void *private_data,
|
---|
103 | uint32_t msg_type,
|
---|
104 | void (*fn)(struct messaging_context *msg,
|
---|
105 | void *private_data,
|
---|
106 | uint32_t msg_type,
|
---|
107 | struct server_id server_id,
|
---|
108 | DATA_BLOB *data));
|
---|
109 | void messaging_deregister(struct messaging_context *ctx, uint32_t msg_type,
|
---|
110 | void *private_data);
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * CAVEAT:
|
---|
114 | *
|
---|
115 | * While the messaging_send*() functions are synchronuous by API,
|
---|
116 | * they trigger a tevent-based loop upon sending bigger messages.
|
---|
117 | *
|
---|
118 | * Hence callers should not use these in purely synchonous code,
|
---|
119 | * but run a tevent_loop instead.
|
---|
120 | */
|
---|
121 | NTSTATUS messaging_send(struct messaging_context *msg_ctx,
|
---|
122 | struct server_id server,
|
---|
123 | uint32_t msg_type, const DATA_BLOB *data);
|
---|
124 |
|
---|
125 | NTSTATUS messaging_send_buf(struct messaging_context *msg_ctx,
|
---|
126 | struct server_id server, uint32_t msg_type,
|
---|
127 | const uint8_t *buf, size_t len);
|
---|
128 | int messaging_send_iov_from(struct messaging_context *msg_ctx,
|
---|
129 | struct server_id src, struct server_id dst,
|
---|
130 | uint32_t msg_type,
|
---|
131 | const struct iovec *iov, int iovlen,
|
---|
132 | const int *fds, size_t num_fds);
|
---|
133 | NTSTATUS messaging_send_iov(struct messaging_context *msg_ctx,
|
---|
134 | struct server_id server, uint32_t msg_type,
|
---|
135 | const struct iovec *iov, int iovlen,
|
---|
136 | const int *fds, size_t num_fds);
|
---|
137 |
|
---|
138 | struct tevent_req *messaging_filtered_read_send(
|
---|
139 | TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
---|
140 | struct messaging_context *msg_ctx,
|
---|
141 | bool (*filter)(struct messaging_rec *rec, void *private_data),
|
---|
142 | void *private_data);
|
---|
143 | int messaging_filtered_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
|
---|
144 | struct messaging_rec **presult);
|
---|
145 |
|
---|
146 | struct tevent_req *messaging_read_send(TALLOC_CTX *mem_ctx,
|
---|
147 | struct tevent_context *ev,
|
---|
148 | struct messaging_context *msg,
|
---|
149 | uint32_t msg_type);
|
---|
150 | int messaging_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
|
---|
151 | struct messaging_rec **presult);
|
---|
152 |
|
---|
153 | struct tevent_req *messaging_handler_send(
|
---|
154 | TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
---|
155 | struct messaging_context *msg_ctx, uint32_t msg_type,
|
---|
156 | bool (*handler)(struct messaging_context *msg_ctx,
|
---|
157 | struct messaging_rec **rec, void *private_data),
|
---|
158 | void *private_data);
|
---|
159 | int messaging_handler_recv(struct tevent_req *req);
|
---|
160 |
|
---|
161 | int messaging_cleanup(struct messaging_context *msg_ctx, pid_t pid);
|
---|
162 |
|
---|
163 | bool messaging_parent_dgm_cleanup_init(struct messaging_context *msg);
|
---|
164 |
|
---|
165 | #include "librpc/gen_ndr/ndr_messaging.h"
|
---|
166 |
|
---|
167 | #endif
|
---|