ctrl: cleanup trap creation
Move common trap create/send code into separate function. Change-Id: Iaadc921b951aeb9b3ad5ab796e13d52017139468
This commit is contained in:
parent
a2861a7428
commit
3142d8d30b
27
ggsn/ggsn.c
27
ggsn/ggsn.c
|
@ -133,18 +133,26 @@ int daemon(int nochdir, int noclose)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool send_trap(const struct gsn_t *gsn, const struct pdp_t *pdp, const struct ippoolm_t *member, const char *var)
|
||||||
|
{
|
||||||
|
char val[NAMESIZE];
|
||||||
|
|
||||||
|
snprintf(val, sizeof(val), "%" PRIu64 ",%s", pdp->imsi, inet_ntoa(member->addr));
|
||||||
|
|
||||||
|
if (ctrl_cmd_send_trap(gsn->ctrl, var, val) < 0) {
|
||||||
|
LOGP(DGGSN, LOGL_ERROR, "Failed to create and send TRAP for IMSI %" PRIu64 " [%s].\n", pdp->imsi, var);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int delete_context(struct pdp_t *pdp)
|
int delete_context(struct pdp_t *pdp)
|
||||||
{
|
{
|
||||||
DEBUGP(DGGSN, "Deleting PDP context\n");
|
DEBUGP(DGGSN, "Deleting PDP context\n");
|
||||||
struct ippoolm_t *member = pdp->peer;
|
struct ippoolm_t *member = pdp->peer;
|
||||||
char v[NAMESIZE];
|
|
||||||
|
|
||||||
if (pdp->peer) {
|
if (pdp->peer) {
|
||||||
snprintf(v, sizeof(v), "%" PRIu64 ",%s", pdp->imsi,
|
send_trap(gsn, pdp, member, "imsi-rem-ip"); /* TRAP with IP removal */
|
||||||
inet_ntoa(member->addr));
|
|
||||||
if (ctrl_cmd_send_trap(gsn->ctrl, "imsi-rem-ip", v) < 0)
|
|
||||||
LOGP(DGGSN, LOGL_ERROR, "Failed to create and send TRAP"
|
|
||||||
" for IMSI %" PRIu64 " PDP deletion.\n", pdp->imsi);
|
|
||||||
ippool_freeip(ippool, (struct ippoolm_t *)pdp->peer);
|
ippool_freeip(ippool, (struct ippoolm_t *)pdp->peer);
|
||||||
} else
|
} else
|
||||||
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Peer not defined!");
|
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Peer not defined!");
|
||||||
|
@ -162,7 +170,6 @@ int create_context_ind(struct pdp_t *pdp)
|
||||||
{
|
{
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
struct ippoolm_t *member;
|
struct ippoolm_t *member;
|
||||||
char v[NAMESIZE];
|
|
||||||
|
|
||||||
DEBUGP(DGGSN, "Received create PDP context request\n");
|
DEBUGP(DGGSN, "Received create PDP context request\n");
|
||||||
|
|
||||||
|
@ -192,10 +199,8 @@ int create_context_ind(struct pdp_t *pdp)
|
||||||
SYS_ERR(DGGSN, LOGL_ERROR, 0,
|
SYS_ERR(DGGSN, LOGL_ERROR, 0,
|
||||||
"Cannot add tunnel to kernel: %s\n", strerror(errno));
|
"Cannot add tunnel to kernel: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
/* FIXME: naming? */
|
|
||||||
snprintf(v, sizeof(v), "%" PRIu64 ",%s", pdp->imsi, inet_ntoa(member->addr));
|
if (!send_trap(gsn, pdp, member, "imsi-ass-ip")) { /* TRAP with IP assignment */
|
||||||
if (ctrl_cmd_send_trap(gsn->ctrl, "imsi-ass-ip", v) < 0) {
|
|
||||||
LOGP(DGGSN, LOGL_ERROR, "Trap creation failed.\n");
|
|
||||||
gtp_create_context_resp(gsn, pdp, GTPCAUSE_NO_RESOURCES);
|
gtp_create_context_resp(gsn, pdp, GTPCAUSE_NO_RESOURCES);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue