gb: Add functions to access the LL part of the NS-VC objects

Adds the functions gprs_ns_ll_copy() and gprs_ns_ll_clear(). Renames
gprs_ns_format_peer() to gprs_ns_ll_str(). All of these functions
uniformly access the link layer part within the NS-VC objects.

Sponsored-by: On-Waves ehf
This commit is contained in:
Jacob Erlbeck 2013-10-14 22:06:47 +02:00 committed by Holger Hans Peter Freyther
parent 6901715124
commit 96550e0321
4 changed files with 52 additions and 12 deletions

View File

@ -177,7 +177,13 @@ void gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause);
int gprs_ns_vty_init(struct gprs_ns_inst *nsi);
/* Resturn peer info as string (NOTE: the buffer is allocated statically) */
const char *gprs_ns_format_peer(struct gprs_nsvc *nsvc);
const char *gprs_ns_ll_str(struct gprs_nsvc *nsvc);
/* Copy the link layer info from other into nsvc */
void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other);
/* Clear the link layer info (will never match a real link then) */
void gprs_ns_ll_clear(struct gprs_nsvc *nsvc);
#define NS_ALLOC_SIZE 2048
#define NS_ALLOC_HEADROOM 20

View File

@ -802,7 +802,7 @@ int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg,
return rc;
}
const char *gprs_ns_format_peer(struct gprs_nsvc *nsvc)
const char *gprs_ns_ll_str(struct gprs_nsvc *nsvc)
{
static char buf[80];
snprintf(buf, sizeof(buf), "%s:%u",
@ -812,6 +812,38 @@ const char *gprs_ns_format_peer(struct gprs_nsvc *nsvc)
return buf;
}
void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other)
{
nsvc->ll = other->ll;
switch (nsvc->ll) {
case GPRS_NS_LL_UDP:
nsvc->ip = other->ip;
break;
case GPRS_NS_LL_FR_GRE:
nsvc->frgre = other->frgre;
break;
default:
break;
}
}
void gprs_ns_ll_clear(struct gprs_nsvc *nsvc)
{
switch (nsvc->ll) {
case GPRS_NS_LL_UDP:
nsvc->ip.bts_addr.sin_addr.s_addr = INADDR_ANY;
nsvc->ip.bts_addr.sin_port = 0;
break;
case GPRS_NS_LL_FR_GRE:
nsvc->frgre.bts_addr.sin_addr.s_addr = INADDR_ANY;
nsvc->frgre.bts_addr.sin_port = 0;
break;
default:
break;
}
}
/*! \brief Create/get NS-VC independently from underlying transport layer
* \param nsi NS instance to which the data belongs
* \param[in] msg message buffer containing newly-received data
@ -841,7 +873,7 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg,
if (nsh->pdu_type == NS_PDUT_STATUS) {
LOGP(DNS, LOGL_INFO, "Ignoring NS STATUS from %s "
"for non-existing NS-VC\n",
gprs_ns_format_peer(fallback_nsvc));
gprs_ns_ll_str(fallback_nsvc));
return GPRS_NS_CS_SKIPPED;
}
@ -851,7 +883,7 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg,
log_set_context(GPRS_CTX_NSVC, fallback_nsvc);
LOGP(DNS, LOGL_INFO, "Rejecting NS PDU type 0x%0x "
"from %s for non-existing NS-VC\n",
nsh->pdu_type, gprs_ns_format_peer(fallback_nsvc));
nsh->pdu_type, gprs_ns_ll_str(fallback_nsvc));
fallback_nsvc->nsvci = fallback_nsvc->nsei = 0xfffe;
fallback_nsvc->state = NSE_S_ALIVE;
@ -859,7 +891,7 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg,
NS_CAUSE_PDU_INCOMP_PSTATE, 0, msg);
if (rc < 0) {
LOGP(DNS, LOGL_ERROR, "TX failed (%d) to peer %s\n",
rc, gprs_ns_format_peer(fallback_nsvc));
rc, gprs_ns_ll_str(fallback_nsvc));
return rc;
}
return GPRS_NS_CS_REJECTED;
@ -887,7 +919,7 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg,
*new_nsvc = gprs_nsvc_create(nsi, 0xffff);
log_set_context(GPRS_CTX_NSVC, *new_nsvc);
LOGP(DNS, LOGL_INFO, "Creating NS-VC for BSS at %s\n",
gprs_ns_format_peer(fallback_nsvc));
gprs_ns_ll_str(fallback_nsvc));
return GPRS_NS_CS_CREATED;
}

View File

@ -54,7 +54,9 @@ gprs_ns_tx_reset;
gprs_ns_tx_status;
gprs_ns_tx_unblock;
gprs_ns_vty_init;
gprs_ns_format_peer;
gprs_ns_ll_str;
gprs_ns_ll_copy;
gprs_ns_ll_clear;
gprs_nsvc_create;
gprs_nsvc_delete;

View File

@ -134,31 +134,31 @@ static int test_signal(unsigned int subsys, unsigned int signal,
case S_NS_RESET:
printf("==> got signal NS_RESET, NS-VC 0x%04x/%s\n",
nssd->nsvc->nsvci,
gprs_ns_format_peer(nssd->nsvc));
gprs_ns_ll_str(nssd->nsvc));
break;
case S_NS_ALIVE_EXP:
printf("==> got signal NS_ALIVE_EXP, NS-VC 0x%04x/%s\n",
nssd->nsvc->nsvci,
gprs_ns_format_peer(nssd->nsvc));
gprs_ns_ll_str(nssd->nsvc));
break;
case S_NS_BLOCK:
printf("==> got signal NS_BLOCK, NS-VC 0x%04x/%s\n",
nssd->nsvc->nsvci,
gprs_ns_format_peer(nssd->nsvc));
gprs_ns_ll_str(nssd->nsvc));
break;
case S_NS_UNBLOCK:
printf("==> got signal NS_UNBLOCK, NS-VC 0x%04x/%s\n",
nssd->nsvc->nsvci,
gprs_ns_format_peer(nssd->nsvc));
gprs_ns_ll_str(nssd->nsvc));
break;
default:
printf("==> got signal %d, NS-VC 0x%04x/%s\n", signal,
nssd->nsvc->nsvci,
gprs_ns_format_peer(nssd->nsvc));
gprs_ns_ll_str(nssd->nsvc));
break;
}