Max has submitted this change and it was merged. Change subject: ctrl: cleanup trap creation ......................................................................
ctrl: cleanup trap creation Move common trap create/send code into separate function. Change-Id: Iaadc921b951aeb9b3ad5ab796e13d52017139468 --- M ggsn/ggsn.c 1 file changed, 16 insertions(+), 11 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 181ba2d..4d07f11 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -133,18 +133,26 @@ } #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) { DEBUGP(DGGSN, "Deleting PDP context\n"); struct ippoolm_t *member = pdp->peer; - char v[NAMESIZE]; if (pdp->peer) { - snprintf(v, sizeof(v), "%" PRIu64 ",%s", pdp->imsi, - 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); + send_trap(gsn, pdp, member, "imsi-rem-ip"); /* TRAP with IP removal */ ippool_freeip(ippool, (struct ippoolm_t *)pdp->peer); } else SYS_ERR(DGGSN, LOGL_ERROR, 0, "Peer not defined!"); @@ -162,7 +170,6 @@ { struct in_addr addr; struct ippoolm_t *member; - char v[NAMESIZE]; DEBUGP(DGGSN, "Received create PDP context request\n"); @@ -192,10 +199,8 @@ SYS_ERR(DGGSN, LOGL_ERROR, 0, "Cannot add tunnel to kernel: %s\n", strerror(errno)); } -/* FIXME: naming? */ - snprintf(v, sizeof(v), "%" PRIu64 ",%s", pdp->imsi, inet_ntoa(member->addr)); - if (ctrl_cmd_send_trap(gsn->ctrl, "imsi-ass-ip", v) < 0) { - LOGP(DGGSN, LOGL_ERROR, "Trap creation failed.\n"); + + if (!send_trap(gsn, pdp, member, "imsi-ass-ip")) { /* TRAP with IP assignment */ gtp_create_context_resp(gsn, pdp, GTPCAUSE_NO_RESOURCES); return 0; } -- To view, visit https://gerrit.osmocom.org/2656 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iaadc921b951aeb9b3ad5ab796e13d52017139468 Gerrit-PatchSet: 1 Gerrit-Project: openggsn Gerrit-Branch: master Gerrit-Owner: Max <msur...@sysmocom.de> Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Max <msur...@sysmocom.de>