0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <utlist.h>
0039
0040 #include <ndrstandard.h>
0041
0042 #include <ndebug.h>
0043 #include <userlog.h>
0044 #include <ndrxd.h>
0045 #include <ndrxdcmn.h>
0046
0047 #include "cmd_processor.h"
0048 #include "bridge_int.h"
0049 #include "atmi_shm.h"
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 expublic int cmd_brcon (command_call_t * call, char *data, size_t len, int context)
0067 {
0068 int ret=EXSUCCEED;
0069 bridge_info_t *brcall = (bridge_info_t *)call;
0070
0071
0072 ndrx_shm_bridge_connected(brcall->nodeid);
0073
0074 brd_connected(brcall->nodeid);
0075
0076 out:
0077 return ret;
0078 }
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 expublic int cmd_brdiscon (command_call_t * call, char *data, size_t len, int context)
0089 {
0090 int ret=EXSUCCEED;
0091 bridge_info_t *brcall = (bridge_info_t *)call;
0092
0093
0094 ndrx_shm_bridge_disco(brcall->nodeid);
0095
0096 brd_discconnected(brcall->nodeid);
0097
0098 out:
0099 return ret;
0100 }
0101
0102
0103
0104
0105
0106
0107
0108 expublic int brd_lock_and_update_shm(int nodeid, char *svc_nm, int count, char mode)
0109 {
0110 int ret=EXSUCCEED;
0111
0112
0113
0114 if (EXSUCCEED!=ndrx_lock_svc_op(__func__))
0115 {
0116 ret=EXFAIL;
0117 goto out;
0118 }
0119
0120 ret=ndrx_shm_install_svc_br(svc_nm, 0,
0121 EXTRUE, nodeid, count, mode, 0);
0122
0123
0124
0125 ndrx_unlock_svc_op(__func__);
0126
0127
0128 out:
0129 return ret;
0130 }
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 expublic int cmd_brrefresh (command_call_t * call, char *data, size_t len, int context)
0141 {
0142 int ret=EXSUCCEED;
0143 bridge_refresh_t *refresh = (bridge_refresh_t *)call;
0144 int i, j;
0145 bridgedef_t* br = brd_get_bridge(call->caller_nodeid);
0146 bridgedef_svcs_t * svc_ent;
0147 bridge_refresh_svc_t *ref_ent;
0148
0149
0150 bridgedef_svcs_t *svcref= NULL;
0151
0152 if (br==NULL)
0153 {
0154 NDRX_LOG(log_error, "Bridge %d not found!", call->caller_nodeid);
0155 goto out;
0156 }
0157
0158
0159 for (i=0; i<refresh->count; i++)
0160 {
0161 NDRX_LOG(log_info, "Got service from node: %d - [%s] count: [%d], mode: [%c]",
0162 refresh->call.caller_nodeid,
0163 refresh->svcs[i].svc_nm,
0164 refresh->svcs[i].count,
0165 refresh->svcs[i].mode);
0166 ref_ent = &refresh->svcs[i];
0167
0168 if (BRIDGE_REFRESH_MODE_FULL==refresh->mode)
0169 {
0170 brd_add_svc_to_hash_g(&svcref, ref_ent->svc_nm);
0171 }
0172
0173
0174
0175
0176
0177
0178 if (EXSUCCEED!=brd_lock_and_update_shm(br->nodeid,
0179 ref_ent->svc_nm, ref_ent->count, ref_ent->mode))
0180 {
0181 NDRX_LOG(log_error, "Failed to update shared mem for [%s]/%d/%c!",
0182 ref_ent->svc_nm, ref_ent->count, ref_ent->mode);
0183 EXFAIL_OUT(ret);
0184 }
0185
0186 if (NULL!=(svc_ent = brd_get_svc_brhash(br, refresh->svcs[i].svc_nm)))
0187 {
0188
0189 if (ref_ent->mode==BRIDGE_REFRESH_MODE_FULL)
0190 {
0191 svc_ent->count=ref_ent->count;
0192 }
0193 else
0194 {
0195
0196 svc_ent->count+=ref_ent->count;
0197 NDRX_LOG(log_debug, "Bridge %d svc hash [%s] count: %d",
0198 br->nodeid, ref_ent->svc_nm, svc_ent->count);
0199 }
0200
0201
0202 if (0==svc_ent->count)
0203 {
0204 NDRX_LOG(log_warn, "Service count 0 - remove from br hash");
0205 brd_del_svc_brhash(br, svc_ent, ref_ent->svc_nm);
0206 }
0207
0208 }
0209 else
0210 {
0211
0212 if (ref_ent->count > 0)
0213 {
0214 NDRX_LOG(log_debug, "Adding service to bridge svc hash");
0215
0216 if (EXSUCCEED!=brd_add_svc_brhash(br, ref_ent->svc_nm,
0217 ref_ent->count))
0218 {
0219 EXFAIL_OUT(ret);
0220 }
0221 }
0222 }
0223 }
0224
0225
0226 if (BRIDGE_REFRESH_MODE_FULL==refresh->mode)
0227 {
0228 bridgedef_svcs_t *r = NULL;
0229 bridgedef_svcs_t *rtmp = NULL;
0230
0231
0232
0233
0234
0235 EXHASH_ITER(hh, br->theyr_services, r, rtmp)
0236 {
0237 NDRX_LOG(log_debug, "Cross checking service [%s] in "
0238 "refresh msg", r->svc_nm);
0239 if (NULL==brd_get_svc(svcref, r->svc_nm))
0240 {
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 NDRX_LOG(log_warn, "Service [%s] not present in refresh "
0252 "message, but we see it our view - there was some packet re-ordering or loss! - "
0253 "Removing it from our view!", r->svc_nm);
0254
0255 brd_lock_and_update_shm(br->nodeid, r->svc_nm, 0, BRIDGE_REFRESH_MODE_FULL);
0256
0257 brd_del_svc_brhash(br, r, r->svc_nm);
0258 }
0259 else
0260 {
0261 NDRX_LOG(log_debug, "Service [%s] present in refresh - OK",
0262 r->svc_nm);
0263 }
0264 }
0265 }
0266
0267 out:
0268
0269
0270 if (NULL!=svcref)
0271 {
0272
0273 brd_erase_svc_hash_g(svcref);
0274 svcref=NULL;
0275 }
0276
0277 return ret;
0278 }
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289 expublic void getbrs_reply_mod(command_reply_t *reply, size_t *send_size, mod_param_t *params)
0290 {
0291 command_reply_getbrs_t * info = (command_reply_getbrs_t *)reply;
0292 bridgedef_t *cur = NULL;
0293 bridgedef_t *rtmp = NULL;
0294 int pos = 0;
0295
0296 reply->msg_type = NDRXD_CALL_TYPE_GETBRS;
0297
0298 *send_size += (sizeof(command_reply_getbrs_t) - sizeof(command_reply_t));
0299
0300 memset(info->nodes, 0, sizeof(info->nodes));
0301
0302 EXHASH_ITER(hh, G_bridge_hash, cur, rtmp)
0303 {
0304 if (cur->connected)
0305 {
0306 info->nodes[pos] = (char)cur->nodeid;
0307 pos++;
0308 }
0309 }
0310
0311 br_dump_nodestack(info->nodes, "Returning list of connected nodes");
0312
0313 NDRX_LOG(log_debug, "magic: %ld", info->rply.magic);
0314 }
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324 expublic int cmd_getbrs (command_call_t * call, char *data, size_t len, int context)
0325 {
0326 int ret=EXSUCCEED;
0327
0328 NDRX_LOG(log_warn, "cmd_getbrs: call flags 0x%x", call->flags);
0329
0330
0331 if (EXSUCCEED!=simple_command_reply(call, ret, 0L, NULL, getbrs_reply_mod,
0332 0L, 0, NULL))
0333 {
0334 userlog("Failed to send reply back to [%s]", call->reply_queue);
0335 }
0336
0337 NDRX_LOG(log_warn, "cmd_getbrs returns with status %d", ret);
0338
0339 out:
0340 return ret;
0341 }
0342