Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
res_pktccops.c File Reference

PacketCable COPS. More...

#include "asterisk.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <arpa/inet.h>
#include <signal.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "asterisk/pktccops.h"
Include dependency graph for res_pktccops.c:

Go to the source code of this file.

Data Structures

struct  cmts_list
 
struct  cops_cmts
 
struct  cops_ippool
 
struct  copsmsg
 
struct  gate_list
 
struct  gatespec
 
struct  ippool_list
 
struct  pktcobj
 

Macros

#define AST_API_MODULE
 
#define COPS_HEADER_SIZE   8
 
#define COPS_OBJECT_HEADER_SIZE   4
 
#define DEFAULT_COPS_PORT   "2126"
 
#define GATE_INFO_OBJ_SIZE   24
 
#define GATE_SET_OBJ_SIZE   144
 
#define GATEID_OBJ_SIZE   8
 
#define PKTCCOPS_DESTROY_CURRENT_GATE
 
#define PKTCCOPS_SCOMMAND_GATE_ALLOC   1
 
#define PKTCCOPS_SCOMMAND_GATE_ALLOC_ACK   2
 
#define PKTCCOPS_SCOMMAND_GATE_ALLOC_ERR   3
 
#define PKTCCOPS_SCOMMAND_GATE_CLOSE   14
 
#define PKTCCOPS_SCOMMAND_GATE_DELETE   10
 
#define PKTCCOPS_SCOMMAND_GATE_DELETE_ACK   11
 
#define PKTCCOPS_SCOMMAND_GATE_DELETE_ERR   12
 
#define PKTCCOPS_SCOMMAND_GATE_INFO   7
 
#define PKTCCOPS_SCOMMAND_GATE_INFO_ACK   8
 
#define PKTCCOPS_SCOMMAND_GATE_INFO_ERR   9
 
#define PKTCCOPS_SCOMMAND_GATE_OPEN   13
 
#define PKTCCOPS_SCOMMAND_GATE_SET   4
 
#define PKTCCOPS_SCOMMAND_GATE_SET_ACK   5
 
#define PKTCCOPS_SCOMMAND_GATE_SET_ERR   6
 
#define SENDFLAGS   MSG_NOSIGNAL | MSG_DONTWAIT
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
struct cops_gate *AST_OPTIONAL_API_NAME() ast_pktccops_gate_alloc (int cmd, struct cops_gate *gate, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, int(*const got_dq_gi)(struct cops_gate *gate), int(*const gate_remove)(struct cops_gate *gate))
 
static int cops_connect (char *host, char *port)
 
static uint16_t cops_construct_gate (int cmd, char *p, uint16_t trid, uint32_t mtahost, uint32_t actcount, float rate, uint32_t psizegateid, uint32_t ssip, uint16_t ssport, uint32_t gateid, struct cops_cmts *cmts)
 
static uint16_t cops_constructgatespec (struct gatespec *gs, char *res)
 
static void cops_freemsg (struct copsmsg *p)
 
static struct cops_gatecops_gate_cmd (int cmd, struct cops_cmts *cmts, uint16_t trid, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, struct cops_gate *gate)
 
static int cops_getmsg (int sfd, struct copsmsg *recmsg)
 
static int cops_sendmsg (int sfd, struct copsmsg *sendmsg)
 
static void * do_pktccops (void *data)
 
static uint32_t ftoieeef (float n)
 
static int load_module (void)
 
static int load_pktccops_config (void)
 
static int pktccops_add_ippool (struct cops_ippool *ippool)
 
static char * pktccops_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * pktccops_gatedel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * pktccops_gateset (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * pktccops_show_cmtses (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * pktccops_show_gates (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * pktccops_show_pools (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void pktccops_unregister_cmtses (void)
 
static void pktccops_unregister_ippools (void)
 
static int reload_module (void)
 
static int restart_pktc_thread (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS , .description = "PktcCOPS manager for MGCP" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload_module, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_pktccops []
 
struct cmts_list cmts_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static uint16_t cops_trid = 0
 
struct gate_list gate_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static int gateinfoperiod = 60
 
static int gatetimeout = 150
 
struct ippool_list ippool_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static uint32_t keepalive = 60
 
static ast_mutex_t pktccops_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static pthread_t pktccops_thread = AST_PTHREADT_NULL
 
static int pktccopsdebug = 0
 
static int pktcreload = 0
 
static uint16_t t1 = 250
 
static uint16_t t7 = 200
 
static uint16_t t8 = 300
 

Detailed Description

PacketCable COPS.

Author
Attila Domjan attil.nosp@m.a.do.nosp@m.mjan..nosp@m.hu@g.nosp@m.mail..nosp@m.com
Note
This module is an add-on to chan_mgcp. It adds support for the PacketCable MGCP variation called NCS. Res_pktccops implements COPS (RFC 2748), a protocol used to manage dynamic bandwith allocation in CMTS's (HFC gateways). When you use NCS, you need to talk COPS with the CMTS to complete the calls.

Definition in file res_pktccops.c.

Macro Definition Documentation

◆ AST_API_MODULE

#define AST_API_MODULE

Definition at line 62 of file res_pktccops.c.

◆ COPS_HEADER_SIZE

#define COPS_HEADER_SIZE   8

Definition at line 67 of file res_pktccops.c.

Referenced by cops_gate_cmd(), cops_getmsg(), cops_sendmsg(), and do_pktccops().

◆ COPS_OBJECT_HEADER_SIZE

#define COPS_OBJECT_HEADER_SIZE   4

Definition at line 68 of file res_pktccops.c.

Referenced by cops_gate_cmd(), cops_getmsg(), and do_pktccops().

◆ DEFAULT_COPS_PORT

#define DEFAULT_COPS_PORT   "2126"

Definition at line 65 of file res_pktccops.c.

Referenced by load_pktccops_config().

◆ GATE_INFO_OBJ_SIZE

#define GATE_INFO_OBJ_SIZE   24

Definition at line 71 of file res_pktccops.c.

Referenced by cops_gate_cmd().

◆ GATE_SET_OBJ_SIZE

#define GATE_SET_OBJ_SIZE   144

Definition at line 69 of file res_pktccops.c.

Referenced by cops_gate_cmd().

◆ GATEID_OBJ_SIZE

#define GATEID_OBJ_SIZE   8

Definition at line 70 of file res_pktccops.c.

Referenced by cops_gate_cmd().

◆ PKTCCOPS_DESTROY_CURRENT_GATE

#define PKTCCOPS_DESTROY_CURRENT_GATE
Value:
if (gate->gate_remove) { \
gate->gate_remove(gate); \
} \
ast_free(gate);
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556

Definition at line 692 of file res_pktccops.c.

Referenced by do_pktccops().

◆ PKTCCOPS_SCOMMAND_GATE_ALLOC

#define PKTCCOPS_SCOMMAND_GATE_ALLOC   1

Definition at line 73 of file res_pktccops.c.

◆ PKTCCOPS_SCOMMAND_GATE_ALLOC_ACK

#define PKTCCOPS_SCOMMAND_GATE_ALLOC_ACK   2

Definition at line 74 of file res_pktccops.c.

◆ PKTCCOPS_SCOMMAND_GATE_ALLOC_ERR

#define PKTCCOPS_SCOMMAND_GATE_ALLOC_ERR   3

Definition at line 75 of file res_pktccops.c.

◆ PKTCCOPS_SCOMMAND_GATE_CLOSE

#define PKTCCOPS_SCOMMAND_GATE_CLOSE   14

Definition at line 86 of file res_pktccops.c.

Referenced by do_pktccops().

◆ PKTCCOPS_SCOMMAND_GATE_DELETE

#define PKTCCOPS_SCOMMAND_GATE_DELETE   10

Definition at line 82 of file res_pktccops.c.

Referenced by cops_construct_gate().

◆ PKTCCOPS_SCOMMAND_GATE_DELETE_ACK

#define PKTCCOPS_SCOMMAND_GATE_DELETE_ACK   11

Definition at line 83 of file res_pktccops.c.

Referenced by do_pktccops().

◆ PKTCCOPS_SCOMMAND_GATE_DELETE_ERR

#define PKTCCOPS_SCOMMAND_GATE_DELETE_ERR   12

Definition at line 84 of file res_pktccops.c.

◆ PKTCCOPS_SCOMMAND_GATE_INFO

#define PKTCCOPS_SCOMMAND_GATE_INFO   7

Definition at line 79 of file res_pktccops.c.

Referenced by cops_construct_gate().

◆ PKTCCOPS_SCOMMAND_GATE_INFO_ACK

#define PKTCCOPS_SCOMMAND_GATE_INFO_ACK   8

Definition at line 80 of file res_pktccops.c.

Referenced by do_pktccops().

◆ PKTCCOPS_SCOMMAND_GATE_INFO_ERR

#define PKTCCOPS_SCOMMAND_GATE_INFO_ERR   9

Definition at line 81 of file res_pktccops.c.

Referenced by do_pktccops().

◆ PKTCCOPS_SCOMMAND_GATE_OPEN

#define PKTCCOPS_SCOMMAND_GATE_OPEN   13

Definition at line 85 of file res_pktccops.c.

Referenced by do_pktccops().

◆ PKTCCOPS_SCOMMAND_GATE_SET

#define PKTCCOPS_SCOMMAND_GATE_SET   4

Definition at line 76 of file res_pktccops.c.

Referenced by cops_construct_gate().

◆ PKTCCOPS_SCOMMAND_GATE_SET_ACK

#define PKTCCOPS_SCOMMAND_GATE_SET_ACK   5

Definition at line 77 of file res_pktccops.c.

Referenced by do_pktccops().

◆ PKTCCOPS_SCOMMAND_GATE_SET_ERR

#define PKTCCOPS_SCOMMAND_GATE_SET_ERR   6

Definition at line 78 of file res_pktccops.c.

Referenced by do_pktccops().

◆ SENDFLAGS

#define SENDFLAGS   MSG_NOSIGNAL | MSG_DONTWAIT

Referenced by cops_sendmsg().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 1516 of file res_pktccops.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 1516 of file res_pktccops.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 1516 of file res_pktccops.c.

◆ ast_pktccops_gate_alloc()

struct cops_gate* AST_OPTIONAL_API_NAME() ast_pktccops_gate_alloc ( int  cmd,
struct cops_gate gate,
uint32_t  mta,
uint32_t  actcount,
float  bitrate,
uint32_t  psize,
uint32_t  ssip,
uint16_t  ssport,
int(*)(struct cops_gate *gate)  got_dq_gi,
int(*)(struct cops_gate *gate)  gate_remove 
)

Definition at line 468 of file res_pktccops.c.

References ast_debug, ast_log, cops_gate_cmd(), cops_trid, cops_gate::gate_remove, GATE_SET_HAVE_GATEID, cops_gate::gateid, cops_gate::got_dq_gi, LOG_WARNING, cops_gate::mta, NULL, and pktcreload.

Referenced by mgcp_alloc_pktcgate(), and mgcp_hangup().

473 {
474  while (pktcreload) {
475  sched_yield();
476  }
477 
478  if (cmd == GATE_SET_HAVE_GATEID && gate) {
479  ast_debug(3, "------- gate modify gateid 0x%x ssip: 0x%x\n", gate->gateid, ssip);
480  /* TODO implement it */
481  ast_log(LOG_WARNING, "Modify GateID not implemented\n");
482  }
483 
484  if ((gate = cops_gate_cmd(cmd, NULL, cops_trid++, mta, actcount, bitrate, psize, ssip, ssport, gate))) {
485  ast_debug(3, "COPS: Allocating gate for mta: 0x%x\n", mta);
486  gate->got_dq_gi = got_dq_gi;
487  gate->gate_remove = gate_remove;
488  return(gate);
489  } else {
490  ast_debug(3, "COPS: Couldn't allocate gate for mta: 0x%x\n", mta);
491  return NULL;
492  }
493 }
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
static struct cops_gate * cops_gate_cmd(int cmd, struct cops_cmts *cmts, uint16_t trid, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, struct cops_gate *gate)
Definition: res_pktccops.c:495
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
uint32_t gateid
Definition: pktccops.h:55
static int pktcreload
Definition: res_pktccops.c:162
static uint16_t cops_trid
Definition: res_pktccops.c:90
int(* gate_remove)(struct cops_gate *gate)
Definition: pktccops.h:65
int(* got_dq_gi)(struct cops_gate *gate)
Definition: pktccops.h:64

◆ cops_connect()

static int cops_connect ( char *  host,
char *  port 
)
static

Definition at line 649 of file res_pktccops.c.

References ast_debug, ast_fd_set_flags, ast_log, LOG_WARNING, NULL, and result.

Referenced by do_pktccops().

650 {
651  int s, sfd = -1;
652  struct addrinfo hints;
653  struct addrinfo *rp;
654  struct addrinfo *result;
655 #ifdef HAVE_SO_NOSIGPIPE
656  int trueval = 1;
657 #endif
658 
659  memset(&hints, 0, sizeof(struct addrinfo));
660 
661  hints.ai_family = AF_UNSPEC;
662  hints.ai_socktype = SOCK_STREAM;
663  hints.ai_flags = 0;
664  hints.ai_protocol = 0;
665 
666  s = getaddrinfo(host, port, &hints, &result);
667  if (s != 0) {
668  ast_log(LOG_WARNING, "COPS: getaddrinfo: %s\n", gai_strerror(s));
669  return -1;
670  }
671 
672  for (rp = result; rp != NULL; rp = rp->ai_next) {
673  sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
674  if (sfd == -1) {
675  ast_log(LOG_WARNING, "Failed socket\n");
676  }
677  ast_fd_set_flags(sfd, O_NONBLOCK);
678 #ifdef HAVE_SO_NOSIGPIPE
679  setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, &trueval, sizeof(trueval));
680 #endif
681  connect(sfd, rp->ai_addr, rp->ai_addrlen);
682  if (sfd == -1) {
683  ast_log(LOG_WARNING, "Failed connect\n");
684  }
685  }
686  freeaddrinfo(result);
687 
688  ast_debug(3, "Connecting to cmts: %s:%s\n", host, port);
689  return(sfd);
690 }
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
Definition: utils.h:1009
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
static char host[256]
Definition: muted.c:77
static PGresult * result
Definition: cel_pgsql.c:88

◆ cops_construct_gate()

static uint16_t cops_construct_gate ( int  cmd,
char *  p,
uint16_t  trid,
uint32_t  mtahost,
uint32_t  actcount,
float  rate,
uint32_t  psizegateid,
uint32_t  ssip,
uint16_t  ssport,
uint32_t  gateid,
struct cops_cmts cmts 
)
static

Definition at line 221 of file res_pktccops.c.

References ast_debug, gatespec::b, cops_constructgatespec(), gatespec::diffserv, gatespec::direction, gatespec::dstip, gatespec::dstp, gatespec::flags, ftoieeef(), GATE_DEL, GATE_INFO, GATE_SET_HAVE_GATEID, gatespec::m, gatespec::mm, gatespec::p, PKTCCOPS_SCOMMAND_GATE_DELETE, PKTCCOPS_SCOMMAND_GATE_INFO, PKTCCOPS_SCOMMAND_GATE_SET, gatespec::protocolid, gatespec::r, gatespec::rate, gatespec::s, gatespec::sessionclass, gatespec::srcip, gatespec::srcp, gatespec::t1, cops_cmts::t1, gatespec::t7, cops_cmts::t7, gatespec::t8, and cops_cmts::t8.

Referenced by cops_gate_cmd().

224 {
225  struct gatespec gs;
226  int offset = 0;
227 
228  ast_debug(3, "CMD: %d\n", cmd);
229 
230  /* Transaction Identifier 8 octets */
231  *(p + offset++) = 0;
232  *(p + offset++) = 8; /* length */
233  *(p + offset++) = 1; /* snum */
234  *(p + offset++) = 1; /* stype */
235  *((uint16_t *) (p + offset)) = htons(trid);
236  offset += 2;
237  *(p + offset++) = 0;
238  *(p + offset++) = (cmd == GATE_DEL) ? PKTCCOPS_SCOMMAND_GATE_DELETE : (cmd != GATE_INFO) ? PKTCCOPS_SCOMMAND_GATE_SET : PKTCCOPS_SCOMMAND_GATE_INFO; /* 4: GATE-SET, 7: GATE-INFO */
239 
240  /*Subscriper Identifier 8 octets */
241  *(p + offset++) = 0;
242  *(p + offset++) = 8; /* length */
243  *(p + offset++) = 2; /* snum */
244  *(p + offset++) = 1; /* stype */
245  *((uint32_t *) (p + offset)) = htonl(mtahost);
246  offset += 4;
247 
248  if (cmd == GATE_INFO || cmd == GATE_SET_HAVE_GATEID || cmd == GATE_DEL) {
249  /* Gate ID 8 Octets */
250  *(p + offset++) = 0;
251  *(p + offset++) = 8; /* length */
252  *(p + offset++) = 3; /* snum */
253  *(p + offset++) = 1; /* stype */
254  *((uint32_t *) (p + offset)) = htonl(gateid);
255  offset += 4;
256  if (cmd == GATE_INFO || cmd == GATE_DEL) {
257  return offset;
258  }
259 
260  }
261 
262  /* Activity Count 8 octets */
263  *(p + offset++) = 0;
264  *(p + offset++) = 8; /* length */
265  *(p + offset++) = 4; /* snum */
266  *(p + offset++) = 1; /* stype */
267  *((uint32_t *) (p + offset)) = htonl(actcount);
268  offset += 4;
269 
270 
271  /* Gate Spec 2*60 Octets */
272  gs.direction = 0; /* DS */
273  gs.protocolid = 17; /* UDP */
274  gs.flags = 0;
275  gs.sessionclass = 1;
276  gs.srcip = htonl(ssip);
277  gs.dstip = htonl(mtahost);
278  gs.srcp = htons(ssport);
279  gs.dstp = 0;
280 /* gs.diffserv = 0xa0;*/
281  gs.diffserv = 0;
282  gs.t1 = htons(cmts->t1);
283  gs.t7 = htons(cmts->t7);
284  gs.t8 = htons(cmts->t8);
285  gs.r = ftoieeef(rate);
286  gs.b = ftoieeef(psizegateid);
287  gs.p = ftoieeef(rate);
288  gs.m = htonl((uint32_t) psizegateid);
289  gs.mm = htonl((uint32_t) psizegateid);
290  gs.rate = ftoieeef(rate);
291  gs.s = htonl(800);
292 
293 
294  *(p + offset) = 0;
295  offset++;
296  *(p + offset) = 60; /* length */
297  offset++;
298  *(p + offset) = 5; /* snum */
299  offset++;
300  *(p + offset) = 1; /* stype */
301  offset++;
302  offset += cops_constructgatespec(&gs, p + offset);
303 
304 
305  gs.direction = 1; /* US */
306  gs.srcip = htonl(mtahost);
307  gs.dstip = htonl(ssip);
308  gs.srcp = 0;
309  gs.dstp = htons(ssport);
310  *(p + offset) = 0;
311  offset++;
312  *(p + offset) = 60; /* length */
313  offset++;
314  *(p + offset) = 5; /* snum */
315  offset++;
316  *(p + offset) = 1; /* stype */
317  offset++;
318  offset += cops_constructgatespec(&gs, p + offset);
319 
320  return(offset);
321 }
#define PKTCCOPS_SCOMMAND_GATE_DELETE
Definition: res_pktccops.c:82
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
static uint32_t ftoieeef(float n)
Definition: res_pktccops.c:175
static uint16_t cops_constructgatespec(struct gatespec *gs, char *res)
Definition: res_pktccops.c:182
uint16_t t7
Definition: res_pktccops.c:138
#define PKTCCOPS_SCOMMAND_GATE_SET
Definition: res_pktccops.c:76
uint16_t t1
Definition: res_pktccops.c:137
#define PKTCCOPS_SCOMMAND_GATE_INFO
Definition: res_pktccops.c:79
uint16_t t8
Definition: res_pktccops.c:139
uint32_t p
Definition: res_pktccops.c:124
uint32_t rate
Definition: res_pktccops.c:127

◆ cops_constructgatespec()

static uint16_t cops_constructgatespec ( struct gatespec gs,
char *  res 
)
static

Definition at line 182 of file res_pktccops.c.

References gatespec::b, gatespec::diffserv, gatespec::direction, gatespec::dstip, gatespec::dstp, gatespec::flags, gatespec::m, gatespec::mm, NULL, gatespec::p, gatespec::protocolid, gatespec::r, gatespec::rate, gatespec::s, gatespec::sessionclass, gatespec::srcip, gatespec::srcp, gatespec::t1, gatespec::t7, and gatespec::t8.

Referenced by cops_construct_gate().

183 {
184  if (res == NULL) {
185  return 0;
186  }
187 
188  *res = (char) gs->direction;
189  *(res + 1) = (char) gs->protocolid;
190  *(res + 2) = (char) gs->flags;
191  *(res + 3) = (char) gs->sessionclass;
192 
193  *((uint32_t *) (res + 4)) = gs->srcip;
194  *((uint32_t *) (res + 8)) = gs->dstip;
195 
196  *((uint16_t *) (res + 12)) = gs->srcp;
197  *((uint16_t *) (res + 14)) = gs->dstp;
198 
199  *(res + 16) = (char) gs->diffserv;
200  *(res + 17) = 0; /* reserved */
201  *(res + 18) = 0; /* reserved */
202  *(res + 19) = 0; /* reserved */
203 
204  *((uint16_t *) (res + 20)) = gs->t1;
205  *(res + 22) = 0; /* reserved */
206  *(res + 23) = 0; /* reserved */
207 
208  *((uint16_t *) (res + 24)) = gs->t7;
209  *((uint16_t *) (res + 26)) = gs->t8;
210 
211  *((uint32_t *) (res + 28)) = gs->r;
212  *((uint32_t *) (res + 32)) = gs->b;
213  *((uint32_t *) (res + 36)) = gs->p;
214  *((uint32_t *) (res + 40)) = gs->m;
215  *((uint32_t *) (res + 44)) = gs->mm;
216  *((uint32_t *) (res + 48)) = gs->rate;
217  *((uint32_t *) (res + 52)) = gs->s;
218  return 56; /* length */
219 };
uint32_t dstip
Definition: res_pktccops.c:115
int diffserv
Definition: res_pktccops.c:118
uint32_t mm
Definition: res_pktccops.c:126
uint16_t t1
Definition: res_pktccops.c:119
uint32_t m
Definition: res_pktccops.c:125
#define NULL
Definition: resample.c:96
uint16_t srcp
Definition: res_pktccops.c:116
uint16_t t7
Definition: res_pktccops.c:120
uint32_t s
Definition: res_pktccops.c:128
int protocolid
Definition: res_pktccops.c:111
uint32_t srcip
Definition: res_pktccops.c:114
uint32_t r
Definition: res_pktccops.c:122
int direction
Definition: res_pktccops.c:110
int sessionclass
Definition: res_pktccops.c:113
uint32_t b
Definition: res_pktccops.c:123
uint32_t p
Definition: res_pktccops.c:124
uint16_t dstp
Definition: res_pktccops.c:117
uint16_t t8
Definition: res_pktccops.c:121
uint32_t rate
Definition: res_pktccops.c:127

◆ cops_freemsg()

static void cops_freemsg ( struct copsmsg p)
static

Definition at line 453 of file res_pktccops.c.

References ast_free, pktcobj::contents, copsmsg::msg, pktcobj::next, NULL, and copsmsg::object.

Referenced by cops_gate_cmd(), and do_pktccops().

454 {
455  struct pktcobj *pnext;
456  ast_free(p->msg);
457  p->msg = NULL;
458  while (p->object != NULL) {
459  pnext = p->object->next;
460  ast_free(p->object->contents);
461  p->object->contents = NULL;
462  ast_free(p->object);
463  p->object = pnext;
464  }
465  p->object = NULL;
466 }
#define NULL
Definition: resample.c:96
char * msg
Definition: res_pktccops.c:106
char * contents
Definition: res_pktccops.c:96
#define ast_free(a)
Definition: astmm.h:182
struct pktcobj * next
Definition: res_pktccops.c:97
struct pktcobj * object
Definition: res_pktccops.c:105

◆ cops_gate_cmd()

static struct cops_gate * cops_gate_cmd ( int  cmd,
struct cops_cmts cmts,
uint16_t  trid,
uint32_t  mta,
uint32_t  actcount,
float  bitrate,
uint32_t  psize,
uint32_t  ssip,
uint16_t  ssport,
struct cops_gate gate 
)
static

Definition at line 495 of file res_pktccops.c.

References ast_calloc, ast_debug, ast_free, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log, ast_malloc, copsmsg::clienttype, cops_gate::cmts, cops_ippool::cmts, pktcobj::cnum, pktcobj::contents, cops_construct_gate(), cops_freemsg(), COPS_HEADER_SIZE, COPS_OBJECT_HEADER_SIZE, cops_sendmsg(), pktcobj::ctype, GATE_ALLOC_PROGRESS, GATE_DEL, GATE_INFO, GATE_INFO_OBJ_SIZE, GATE_SET, GATE_SET_HAVE_GATEID, GATE_SET_OBJ_SIZE, cops_gate::gateid, GATEID_OBJ_SIZE, cops_cmts::handle, cops_gate::in_transaction, pktcobj::length, copsmsg::length, cops_ippool::list, LOG_WARNING, copsmsg::msg, cops_cmts::name, pktcobj::next, NULL, copsmsg::object, copsmsg::opcode, pktccopsdebug, cops_cmts::sfd, cops_ippool::start, stop, cops_gate::trid, and copsmsg::verflag.

Referenced by ast_pktccops_gate_alloc(), do_pktccops(), pktccops_gatedel(), and pktccops_gateset().

498 {
499  struct copsmsg *gateset;
500  struct cops_gate *new;
501  struct cops_ippool *ippool;
502 
503  if (cmd == GATE_DEL) {
504  if (gate == NULL) {
505  return NULL;
506  } else {
507  cmts = gate->cmts;
508  }
509  }
510 
511  if (!cmts) {
513  AST_LIST_TRAVERSE(&ippool_list, ippool, list) {
514  if (mta >= ippool->start && mta <= ippool->stop) {
515  cmts = ippool->cmts;
516  break;
517  }
518  }
520  if (!cmts) {
521  ast_log(LOG_WARNING, "COPS: couldn't find cmts for mta: 0x%x\n", mta);
522  return NULL;
523  }
524  if (cmts->sfd < 0) {
525  ast_log(LOG_WARNING, "CMTS: %s not connected\n", cmts->name);
526  return NULL;
527  }
528  }
529 
530  if (cmd == GATE_SET) {
531  new = ast_calloc(1, sizeof(*new));
532  new->gateid = 0;
533  new->trid = trid;
534  new->mta = mta;
535  new->state = GATE_ALLOC_PROGRESS;
536  new->checked = time(NULL);
537  new->allocated = time(NULL);
538  new->cmts = cmts;
539  new->got_dq_gi = NULL;
540  new->gate_remove = NULL;
541  new->gate_open = NULL;
542  new->tech_pvt = NULL;
543  new->deltimer = 0;
547  gate = new;
548  } else {
549  if (gate) {
550  gate->trid = trid;
551  }
552  }
553 
554  gate->in_transaction = time(NULL);
555 
556  if (!(gateset = ast_malloc(sizeof(struct copsmsg)))) {
557  ast_free(gateset);
558  return NULL;
559  }
560  gateset->msg = NULL;
561  gateset->verflag = 0x10;
562  gateset->opcode = 2; /* Decision */
563  gateset->clienttype = 0x8008; /* =PacketCable */
564 
565  /* Handle object */
566  gateset->object = ast_malloc(sizeof(struct pktcobj));
567  if (!gateset->object) {
568  cops_freemsg(gateset);
569  ast_free(gateset);
570  return NULL;
571  }
572  gateset->object->length = COPS_OBJECT_HEADER_SIZE + 4;
573  gateset->object->cnum = 1; /* Handle */
574  gateset->object->ctype = 1; /* client */
575  if (!(gateset->object->contents = ast_malloc(sizeof(uint32_t)))) {
576  cops_freemsg(gateset);
577  ast_free(gateset);
578  return NULL;
579  }
580  *((uint32_t *) gateset->object->contents) = htonl(cmts->handle);
581 
582  /* Context Object */
583  if (!(gateset->object->next = ast_malloc(sizeof(struct pktcobj)))) {
584  cops_freemsg(gateset);
585  ast_free(gateset);
586  return NULL;
587  }
588  gateset->object->next->length = COPS_OBJECT_HEADER_SIZE + 4;
589  gateset->object->next->cnum = 2; /* Context */
590  gateset->object->next->ctype = 1; /* Context */
591  if (!(gateset->object->next->contents = ast_malloc(sizeof(uint32_t)))) {
592  cops_freemsg(gateset);
593  ast_free(gateset);
594  return NULL;
595  }
596  *((uint32_t *) gateset->object->next->contents) = htonl(0x00080000); /* R-Type = 8 configuration request, M-Type = 0 */
597 
598  /* Decision Object: Flags */
599  if (!(gateset->object->next->next = ast_malloc(sizeof(struct pktcobj)))) {
600  cops_freemsg(gateset);
601  ast_free(gateset);
602  return NULL;
603  }
604  gateset->object->next->next->length = COPS_OBJECT_HEADER_SIZE + 4;
605  gateset->object->next->next->cnum = 6; /* Decision */
606  gateset->object->next->next->ctype = 1; /* Flags */
607  if (!(gateset->object->next->next->contents = ast_malloc(sizeof(uint32_t)))) {
608  cops_freemsg(gateset);
609  ast_free(gateset);
610  return NULL;
611  }
612  *((uint32_t *) gateset->object->next->next->contents) = htonl(0x00010001); /* Install, Trigger Error */
613 
614  /* Decision Object: Data */
615  if (!(gateset->object->next->next->next = ast_malloc(sizeof(struct pktcobj)))) {
616  cops_freemsg(gateset);
617  ast_free(gateset);
618  return NULL;
619  }
621  gateset->object->next->next->next->cnum = 6; /* Decision */
622  gateset->object->next->next->next->ctype = 4; /* Decision Data */
624  if (!gateset->object->next->next->next->contents) {
625  cops_freemsg(gateset);
626  ast_free(gateset);
627  return NULL;
628  }
629  gateset->object->next->next->next->next = NULL;
630 
631  gateset->length = COPS_HEADER_SIZE + gateset->object->length + gateset->object->next->length + gateset->object->next->next->length + gateset->object->next->next->next->length;
632 
633  if ((cmd == GATE_INFO || cmd == GATE_SET_HAVE_GATEID || cmd == GATE_DEL) && gate) {
634  ast_debug(1, "Construct gate with gateid: 0x%x\n", gate->gateid);
635  cops_construct_gate(cmd, gateset->object->next->next->next->contents, trid, mta, actcount, bitrate, psize, ssip, ssport, gate->gateid, cmts);
636  } else {
637  ast_debug(1, "Construct new gate\n");
638  cops_construct_gate(cmd, gateset->object->next->next->next->contents, trid, mta, actcount, bitrate, psize, ssip, ssport, 0, cmts);
639  }
640  if (pktccopsdebug) {
641  ast_debug(3, "send cmd\n");
642  }
643  cops_sendmsg(cmts->sfd, gateset);
644  cops_freemsg(gateset);
645  ast_free(gateset);
646  return gate;
647 }
uint32_t length
Definition: res_pktccops.c:104
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
static int cops_sendmsg(int sfd, struct copsmsg *sendmsg)
Definition: res_pktccops.c:388
unsigned char opcode
Definition: res_pktccops.c:102
struct cops_ippool::@490 list
static void cops_freemsg(struct copsmsg *p)
Definition: res_pktccops.c:453
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
unsigned int stop
Definition: app_meetme.c:1096
char name[80]
Definition: res_pktccops.c:134
uint32_t handle
Definition: res_pktccops.c:142
#define COPS_HEADER_SIZE
Definition: res_pktccops.c:67
#define NULL
Definition: resample.c:96
char * msg
Definition: res_pktccops.c:106
uint32_t start
Definition: res_pktccops.c:152
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define GATE_SET_OBJ_SIZE
Definition: res_pktccops.c:69
char * contents
Definition: res_pktccops.c:96
#define COPS_OBJECT_HEADER_SIZE
Definition: res_pktccops.c:68
uint16_t trid
Definition: pktccops.h:56
#define GATE_INFO_OBJ_SIZE
Definition: res_pktccops.c:71
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
time_t in_transaction
Definition: pktccops.h:57
unsigned char ctype
Definition: res_pktccops.c:95
uint32_t gateid
Definition: pktccops.h:55
uint16_t length
Definition: res_pktccops.c:93
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct cops_cmts * cmts
Definition: res_pktccops.c:154
struct pktcobj * next
Definition: res_pktccops.c:97
struct pktcobj * object
Definition: res_pktccops.c:105
#define GATEID_OBJ_SIZE
Definition: res_pktccops.c:70
unsigned char verflag
Definition: res_pktccops.c:101
static int pktccopsdebug
Definition: res_pktccops.c:161
uint16_t clienttype
Definition: res_pktccops.c:103
unsigned char cnum
Definition: res_pktccops.c:94
static uint16_t cops_construct_gate(int cmd, char *p, uint16_t trid, uint32_t mtahost, uint32_t actcount, float rate, uint32_t psizegateid, uint32_t ssip, uint16_t ssport, uint32_t gateid, struct cops_cmts *cmts)
Definition: res_pktccops.c:221
struct cops_cmts * cmts
Definition: pktccops.h:63

◆ cops_getmsg()

static int cops_getmsg ( int  sfd,
struct copsmsg recmsg 
)
static

Definition at line 323 of file res_pktccops.c.

References ast_debug, ast_malloc, buf, copsmsg::clienttype, pktcobj::cnum, pktcobj::contents, COPS_HEADER_SIZE, COPS_OBJECT_HEADER_SIZE, pktcobj::ctype, len(), pktcobj::length, copsmsg::length, copsmsg::msg, pktcobj::next, NULL, copsmsg::object, copsmsg::opcode, and copsmsg::verflag.

Referenced by do_pktccops().

324 {
325  int len, lent;
326  char buf[COPS_HEADER_SIZE];
327  struct pktcobj *pobject = NULL;
328  uint16_t *ubuf = (uint16_t *) buf;
329  recmsg->msg = NULL;
330  recmsg->object = NULL;
331  len = recv(sfd, buf, COPS_HEADER_SIZE, MSG_DONTWAIT);
332  if (len < COPS_HEADER_SIZE) {
333  return len;
334  }
335  recmsg->verflag = *buf;
336  recmsg->opcode = *(buf + 1);
337  recmsg->clienttype = ntohs(*((uint16_t *) (buf + 2)));
338  recmsg->length = ntohl(*((uint32_t *) (buf + 4)));
339  /* Eg KA msg*/
340  if (recmsg->clienttype != 0x8008 ) {
341  if (!(recmsg->msg = ast_malloc(recmsg->length - COPS_HEADER_SIZE))) {
342  return -1;
343  }
344  lent = recv(sfd, recmsg->msg, recmsg->length - COPS_HEADER_SIZE, MSG_DONTWAIT);
345  if (lent < recmsg->length - COPS_HEADER_SIZE) {
346  return lent;
347  }
348  len += len;
349  } else {
350  /* PacketCable Objects */
351  while (len < recmsg->length) {
352  if (len == COPS_HEADER_SIZE) {
353  /* 1st round */
354  if (!(recmsg->object = ast_malloc(sizeof(struct pktcobj)))) {
355  return -1;
356  }
357  pobject = recmsg->object;
358  } else {
359  if (!(pobject->next = ast_malloc(sizeof(struct pktcobj)))) {
360  return -1;
361  }
362  pobject = pobject->next;
363  }
364  pobject->next = NULL;
365  lent = recv(sfd, buf, COPS_OBJECT_HEADER_SIZE, MSG_DONTWAIT);
366  if (lent < COPS_OBJECT_HEADER_SIZE) {
367  ast_debug(3, "Too short object header len: %i\n", lent);
368  return lent;
369  }
370  len += lent;
371  pobject->length = ntohs(*ubuf);
372  pobject->cnum = *(buf + 2);
373  pobject->ctype = *(buf + 3);
374  if (!(pobject->contents = ast_malloc(pobject->length - COPS_OBJECT_HEADER_SIZE))) {
375  return -1;
376  }
377  lent = recv(sfd, pobject->contents, pobject->length - COPS_OBJECT_HEADER_SIZE, MSG_DONTWAIT);
378  if (lent < pobject->length - COPS_OBJECT_HEADER_SIZE) {
379  ast_debug(3, "Too short object content len: %i\n", lent);
380  return lent;
381  }
382  len += lent;
383  }
384  }
385  return len;
386 }
uint32_t length
Definition: res_pktccops.c:104
unsigned char opcode
Definition: res_pktccops.c:102
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define COPS_HEADER_SIZE
Definition: res_pktccops.c:67
#define NULL
Definition: resample.c:96
char * msg
Definition: res_pktccops.c:106
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
char * contents
Definition: res_pktccops.c:96
#define COPS_OBJECT_HEADER_SIZE
Definition: res_pktccops.c:68
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
unsigned char ctype
Definition: res_pktccops.c:95
uint16_t length
Definition: res_pktccops.c:93
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct pktcobj * next
Definition: res_pktccops.c:97
struct pktcobj * object
Definition: res_pktccops.c:105
unsigned char verflag
Definition: res_pktccops.c:101
uint16_t clienttype
Definition: res_pktccops.c:103
unsigned char cnum
Definition: res_pktccops.c:94

◆ cops_sendmsg()

static int cops_sendmsg ( int  sfd,
struct copsmsg sendmsg 
)
static

Definition at line 388 of file res_pktccops.c.

References ast_debug, ast_free, ast_log, ast_malloc, buf, copsmsg::clienttype, pktcobj::cnum, pktcobj::contents, COPS_HEADER_SIZE, pktcobj::ctype, errno, pktcobj::length, copsmsg::length, LOG_WARNING, copsmsg::msg, pktcobj::next, NULL, copsmsg::object, copsmsg::opcode, SENDFLAGS, and copsmsg::verflag.

Referenced by cops_gate_cmd(), and do_pktccops().

389 {
390  char *buf;
391  int bufpos;
392  struct pktcobj *pobject;
393 
394  if (sfd < 0) {
395  return -1;
396  }
397 
398  ast_debug(3, "COPS: sending opcode: %i len: %u\n", sendmsg->opcode, sendmsg->length);
399  if (sendmsg->length < COPS_HEADER_SIZE) {
400  ast_log(LOG_WARNING, "COPS: invalid msg size!!!\n");
401  return -1;
402  }
403  if (!(buf = ast_malloc((size_t) sendmsg->length))) {
404  return -1;
405  }
406  *buf = sendmsg->verflag ;
407  *(buf + 1) = sendmsg->opcode;
408  *((uint16_t *)(buf + 2)) = htons(sendmsg->clienttype);
409  *((uint32_t *)(buf + 4)) = htonl(sendmsg->length);
410 
411  if (sendmsg->msg != NULL) {
412  memcpy(buf + COPS_HEADER_SIZE, sendmsg->msg, sendmsg->length - COPS_HEADER_SIZE);
413  } else if (sendmsg->object != NULL) {
414  bufpos = 8;
415  pobject = sendmsg->object;
416  while(pobject != NULL) {
417  ast_debug(3, "COPS: Sending Object : cnum: %i ctype %i len: %i\n", pobject->cnum, pobject->ctype, pobject->length);
418  if (sendmsg->length < bufpos + pobject->length) {
419  ast_log(LOG_WARNING, "COPS: Invalid msg size len: %u objectlen: %i\n", sendmsg->length, pobject->length);
420  ast_free(buf);
421  return -1;
422  }
423  *(uint16_t *) (buf + bufpos) = htons(pobject->length);
424  *(buf + bufpos + 2) = pobject->cnum;
425  *(buf + bufpos + 3) = pobject->ctype;
426  if (sendmsg->length < pobject->length + bufpos) {
427  ast_log(LOG_WARNING, "COPS: Error sum of object len more the msg len %u < %i\n", sendmsg->length, pobject->length + bufpos);
428  ast_free(buf);
429  return -1;
430  }
431  memcpy((buf + bufpos + 4), pobject->contents, pobject->length - 4);
432  bufpos += pobject->length;
433  pobject = pobject->next;
434  }
435  }
436 
437  errno = 0;
438 #ifdef HAVE_MSG_NOSIGNAL
439 #define SENDFLAGS MSG_NOSIGNAL | MSG_DONTWAIT
440 #else
441 #define SENDFLAGS MSG_DONTWAIT
442 #endif
443  if (send(sfd, buf, sendmsg->length, SENDFLAGS) == -1) {
444  ast_log(LOG_WARNING, "COPS: Send failed errno=%i\n", errno);
445  ast_free(buf);
446  return -2;
447  }
448 #undef SENDFLAGS
449  ast_free(buf);
450  return 0;
451 }
uint32_t length
Definition: res_pktccops.c:104
unsigned char opcode
Definition: res_pktccops.c:102
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define COPS_HEADER_SIZE
Definition: res_pktccops.c:67
#define NULL
Definition: resample.c:96
char * msg
Definition: res_pktccops.c:106
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
char * contents
Definition: res_pktccops.c:96
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
unsigned char ctype
Definition: res_pktccops.c:95
uint16_t length
Definition: res_pktccops.c:93
int errno
#define ast_free(a)
Definition: astmm.h:182
struct pktcobj * next
Definition: res_pktccops.c:97
struct pktcobj * object
Definition: res_pktccops.c:105
unsigned char verflag
Definition: res_pktccops.c:101
uint16_t clienttype
Definition: res_pktccops.c:103
#define SENDFLAGS
unsigned char cnum
Definition: res_pktccops.c:94

◆ do_pktccops()

static void* do_pktccops ( void *  data)
static

Definition at line 699 of file res_pktccops.c.

References ast_debug, ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log, ast_malloc, ast_poll, ast_poll_fd_index(), ast_realloc, cops_gate::checked, copsmsg::clienttype, cops_gate::cmts, pktcobj::cnum, pktcobj::contents, cops_connect(), cops_freemsg(), cops_gate_cmd(), cops_getmsg(), COPS_HEADER_SIZE, COPS_OBJECT_HEADER_SIZE, cops_sendmsg(), cops_trid, pktcobj::ctype, cops_gate::deltimer, GATE_ALLOC_FAILED, GATE_ALLOCATED, GATE_CLOSED, GATE_CLOSED_ERR, GATE_DEL, GATE_DELETED, GATE_INFO, GATE_OPEN, cops_gate::gate_open, GATE_TIMEOUT, cops_gate::gateid, gateinfoperiod, gatetimeout, cops_gate::got_dq_gi, cops_cmts::handle, cops_cmts::host, cops_gate::in_transaction, cops_cmts::katimer, cops_cmts::keepalive, len(), pktcobj::length, copsmsg::length, load_pktccops_config(), LOG_WARNING, copsmsg::msg, cops_gate::mta, cops_cmts::name, cops_cmts::need_delete, pktcobj::next, NULL, copsmsg::object, copsmsg::opcode, PKTCCOPS_DESTROY_CURRENT_GATE, PKTCCOPS_SCOMMAND_GATE_CLOSE, PKTCCOPS_SCOMMAND_GATE_DELETE_ACK, PKTCCOPS_SCOMMAND_GATE_INFO_ACK, PKTCCOPS_SCOMMAND_GATE_INFO_ERR, PKTCCOPS_SCOMMAND_GATE_OPEN, PKTCCOPS_SCOMMAND_GATE_SET_ACK, PKTCCOPS_SCOMMAND_GATE_SET_ERR, pktccops_unregister_ippools(), pktcreload, cops_cmts::port, cops_cmts::sfd, cops_gate::state, cops_cmts::state, tmp(), cops_gate::trid, and copsmsg::verflag.

Referenced by restart_pktc_thread().

700 {
701  int res, nfds, len;
702  struct copsmsg *recmsg, *sendmsg;
703  struct copsmsg recmsgb, sendmsgb;
704  struct pollfd *pfds = NULL, *tmp;
705  struct pktcobj *pobject;
706  struct cops_cmts *cmts;
707  struct cops_gate *gate;
708  char *sobjp;
709  uint16_t snst, sobjlen, scommand, recvtrid, actcount, reason, subreason;
710  uint32_t gateid, subscrid, pktcerror;
711  time_t last_exec = 0;
712 
713  recmsg = &recmsgb;
714  sendmsg = &sendmsgb;
715 
716  ast_debug(3, "COPS: thread started\n");
717 
718  for (;;) {
719  ast_free(pfds);
720  pfds = NULL;
721  nfds = 0;
723  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
724  if (last_exec != time(NULL)) {
725  if (cmts->state == 2 && cmts->katimer + cmts->keepalive < time(NULL)) {
726  ast_log(LOG_WARNING, "KA timer (%us) expired cmts: %s\n", cmts->keepalive, cmts->name);
727  cmts->state = 0;
728  cmts->katimer = -1;
729  close(cmts->sfd);
730  cmts->sfd = -1;
731  }
732  }
733  if (cmts->sfd > 0) {
734  if (!(tmp = ast_realloc(pfds, (nfds + 1) * sizeof(*pfds)))) {
735  continue;
736  }
737  pfds = tmp;
738  pfds[nfds].fd = cmts->sfd;
739  pfds[nfds].events = POLLIN;
740  pfds[nfds].revents = 0;
741  nfds++;
742  } else {
743  cmts->sfd = cops_connect(cmts->host, cmts->port);
744  if (cmts->sfd > 0) {
745  cmts->state = 1;
746  if (cmts->sfd > 0) {
747  if (!(tmp = ast_realloc(pfds, (nfds + 1) * sizeof(*pfds)))) {
748  continue;
749  }
750  pfds = tmp;
751  pfds[nfds].fd = cmts->sfd;
752  pfds[nfds].events = POLLIN;
753  pfds[nfds].revents = 0;
754  nfds++;
755  }
756  }
757  }
758  }
760 
761  if (last_exec != time(NULL)) {
762  last_exec = time(NULL);
765  if (gate) {
766  if (gate->deltimer && gate->deltimer < time(NULL)) {
767  gate->deltimer = time(NULL) + 5;
768  gate->trid = cops_trid++;
769  cops_gate_cmd(GATE_DEL, gate->cmts, gate->trid, 0, 0, 0, 0, 0, 0, gate);
770  ast_debug(3, "COPS: requested Gate-Del: CMTS: %s gateid: 0x%x\n", (gate->cmts) ? gate->cmts->name : "null", gate->gateid);
771  }
772  if (time(NULL) - gate->checked > gatetimeout) {
773  ast_debug(3, "COPS: remove from list GATE, CMTS: %s gateid: 0x%x\n", (gate->cmts) ? gate->cmts->name : "null", gate->gateid);
774  gate->state = GATE_TIMEOUT;
776  } else if (time(NULL) - gate->checked > gateinfoperiod && (gate->state == GATE_ALLOCATED || gate->state == GATE_OPEN)) {
777  if (gate->cmts && (!gate->in_transaction || ( gate->in_transaction + 5 ) < time(NULL))) {
778  gate->trid = cops_trid++;
779  ast_debug(3, "COPS: Gate-Info send to CMTS: %s gateid: 0x%x\n", gate->cmts->name, gate->gateid);
780  cops_gate_cmd(GATE_INFO, gate->cmts, gate->trid, gate->mta, 0, 0, 0, 0, 0, gate);
781  }
782  }
783  }
784  }
787  }
788 
789  if (pktcreload == 2) {
790  pktcreload = 0;
791  }
792  if ((res = ast_poll(pfds, nfds, 1000))) {
794  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
795  int idx;
796  if ((idx = ast_poll_fd_index(pfds, nfds, cmts->sfd)) > -1 && (pfds[idx].revents & POLLIN)) {
797  len = cops_getmsg(cmts->sfd, recmsg);
798  if (len > 0) {
799  ast_debug(3, "COPS: got from %s:\n Header: versflag=0x%02hhx opcode=%i clienttype=0x%04hx msglength=%u\n",
800  cmts->name, recmsg->verflag,
801  recmsg->opcode, recmsg->clienttype, recmsg->length);
802  if (recmsg->object != NULL) {
803  pobject = recmsg->object;
804  while (pobject != NULL) {
805  ast_debug(3, " OBJECT: length=%i cnum=%i ctype=%i\n", pobject->length, pobject->cnum, pobject->ctype);
806  if (recmsg->opcode == 1 && pobject->cnum == 1 && pobject->ctype == 1 ) {
807  cmts->handle = ntohl(*((uint32_t *) pobject->contents));
808  ast_debug(3, " REQ client handle: %u\n", cmts->handle);
809  cmts->state = 2;
810  cmts->katimer = time(NULL);
811  } else if (pobject->cnum == 9 && pobject->ctype == 1) {
812  sobjp = pobject->contents;
813  subscrid = 0;
814  recvtrid = 0;
815  scommand = 0;
816  pktcerror = 0;
817  actcount = 0;
818  gateid = 0;
819  reason = 0;
820  subreason = 0;
821  while (sobjp < (pobject->contents + pobject->length - 4)) {
822  sobjlen = ntohs(*((uint16_t *) sobjp));
823  snst = ntohs(*((uint16_t *) (sobjp + 2)));
824  ast_debug(3, " S-Num S-type: 0x%.4x len: %i\n", (unsigned)snst, sobjlen);
825  if (snst == 0x0101 ) {
826  recvtrid = ntohs(*((uint16_t *) (sobjp + 4)));
827  scommand = ntohs(*((uint16_t *) (sobjp + 6)));
828  ast_debug(3, " Transaction Identifier command: %i trid %i\n", scommand, recvtrid);
829  } else if (snst == 0x0201) {
830  subscrid = ntohl(*((uint32_t *) (sobjp + 4)));
831  ast_debug(3, " Subscriber ID: 0x%.8x\n", subscrid);
832  } else if (snst == 0x0301) {
833  gateid = ntohl(*((uint32_t *) (sobjp + 4)));
834  ast_debug(3, " Gate ID: 0x%x 0x%.8x\n", gateid, gateid);
835  } else if (snst == 0x0401) {
836  actcount = ntohs(*((uint16_t *) (sobjp + 6)));
837  ast_debug(3, " Activity Count: %i\n", actcount);
838  } else if (snst == 0x0901) {
839  pktcerror = ntohl(*((uint32_t *) (sobjp + 4)));
840  ast_debug(3, " PKTC Error: 0x%.8x\n", pktcerror);
841  } else if (snst == 0x0d01) {
842  reason = ntohs(*((uint16_t *) (sobjp + 4)));
843  subreason = ntohs(*((uint16_t *) (sobjp + 6)));
844  ast_debug(3, " Reason: %d Subreason: %d\n", reason, subreason);
845  }
846  sobjp += sobjlen;
847  if (!sobjlen)
848  break;
849  }
850  if (scommand == PKTCCOPS_SCOMMAND_GATE_CLOSE || scommand == PKTCCOPS_SCOMMAND_GATE_OPEN) {
853  if (gate->cmts == cmts && gate->gateid == gateid) {
854  if (scommand == PKTCCOPS_SCOMMAND_GATE_CLOSE && gate->state != GATE_CLOSED && gate->state != GATE_CLOSED_ERR ) {
855  ast_debug(3, "COPS Gate Close Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
856  if (subreason) {
857  gate->state = GATE_CLOSED_ERR;
859  } else {
860  gate->state = GATE_CLOSED;
862  }
863  break;
864  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_OPEN && gate->state == GATE_ALLOCATED) {
865  ast_debug(3, "COPS Gate Open Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
866  gate->state = GATE_OPEN;
867  if (gate->gate_open) {
868  ast_debug(3, "Calling GATE-OPEN callback function\n");
869  gate->gate_open(gate);
870  gate->gate_open = NULL;
871  }
872  break;
873  }
874  }
875  }
881  if (gate->cmts == cmts && gate->trid == recvtrid) {
882  gate->gateid = gateid;
883  gate->checked = time(NULL);
884  if (scommand == PKTCCOPS_SCOMMAND_GATE_SET_ACK) {
885  ast_debug(3, "COPS Gate Set Ack Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
886  gate->state = GATE_ALLOCATED;
887  if (gate->got_dq_gi) {
888  gate->got_dq_gi(gate);
889  gate->got_dq_gi = NULL;
890  }
891  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_SET_ERR) {
892  ast_debug(3, "COPS Gate Set Error TrId: %i ErrorCode: 0x%.8x CMTS: %s\n ", recvtrid, pktcerror, cmts->name);
893  gate->state = GATE_ALLOC_FAILED;
894  if (gate->got_dq_gi) {
895  gate->got_dq_gi(gate);
896  gate->got_dq_gi = NULL;
897  }
899  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_INFO_ACK) {
900  ast_debug(3, "COPS Gate Info Ack Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
901  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_INFO_ERR) {
902  ast_debug(3, "COPS Gate Info Error Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
903  gate->state = GATE_ALLOC_FAILED;
905  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_DELETE_ACK) {
906  ast_debug(3, "COPS Gate Deleted Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
907  gate->state = GATE_DELETED;
909  }
910  gate->in_transaction = 0;
911  break;
912  }
913  }
916  }
917  }
918  pobject = pobject->next;
919  }
920  }
921 
922  if (recmsg->opcode == 6 && recmsg->object && recmsg->object->cnum == 11 && recmsg->object->ctype == 1) {
923  ast_debug(3, "COPS: Client open %s\n", cmts->name);
924  sendmsg->msg = NULL;
925  sendmsg->verflag = 0x10;
926  sendmsg->opcode = 7; /* Client Accept */
927  sendmsg->clienttype = 0x8008; /* =PacketCable */
929  sendmsg->object = ast_malloc(sizeof(struct pktcobj));
930  sendmsg->object->length = 4 + COPS_OBJECT_HEADER_SIZE;
931  sendmsg->object->cnum = 10; /* keppalive timer*/
932  sendmsg->object->ctype = 1;
933  sendmsg->object->contents = ast_malloc(sizeof(uint32_t));
934  *((uint32_t *) sendmsg->object->contents) = htonl(cmts->keepalive & 0x0000ffff);
935  sendmsg->object->next = NULL;
936  cops_sendmsg(cmts->sfd, sendmsg);
937  cops_freemsg(sendmsg);
938  } else if (recmsg->opcode == 9) {
939  ast_debug(3, "COPS: Keepalive Request got echoing back %s\n", cmts->name);
940  cops_sendmsg(cmts->sfd, recmsg);
941  cmts->state = 2;
942  cmts->katimer = time(NULL);
943  }
944  }
945  if (len <= 0) {
946  ast_debug(3, "COPS: lost connection to %s\n", cmts->name);
947  close(cmts->sfd);
948  cmts->sfd = -1;
949  cmts->state = 0;
950  }
951  cops_freemsg(recmsg);
952  }
953  }
955  }
956  if (pktcreload) {
957  ast_debug(3, "Reloading pktccops...\n");
961  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
962  cmts->need_delete = 1;
963  }
966  if (cmts && cmts->need_delete) {
967  AST_LIST_TRAVERSE(&gate_list, gate, list) {
968  if (gate->cmts == cmts) {
969  ast_debug(3, "Null gate %s\n", gate->cmts->name);
970  gate->cmts = NULL;
971  }
972  gate->in_transaction = 0;
973  }
975  ast_debug(3, "removing cmts: %s\n", cmts->name);
976  if (cmts->sfd > 0) {
977  close(cmts->sfd);
978  }
980  ast_free(cmts);
981  }
982  }
986  pktcreload = 2;
987  }
988  pthread_testcancel();
989  }
990  return NULL;
991 }
uint32_t length
Definition: res_pktccops.c:104
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define ast_realloc(p, len)
A wrapper for realloc()
Definition: astmm.h:228
static int cops_sendmsg(int sfd, struct copsmsg *sendmsg)
Definition: res_pktccops.c:388
unsigned char opcode
Definition: res_pktccops.c:102
int state
Definition: pktccops.h:59
time_t katimer
Definition: res_pktccops.c:145
static int gatetimeout
Definition: res_pktccops.c:164
#define PKTCCOPS_SCOMMAND_GATE_SET_ERR
Definition: res_pktccops.c:78
static int cops_connect(char *host, char *port)
Definition: res_pktccops.c:649
static int gateinfoperiod
Definition: res_pktccops.c:163
static void cops_freemsg(struct copsmsg *p)
Definition: res_pktccops.c:453
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static int tmp()
Definition: bt_open.c:389
#define PKTCCOPS_DESTROY_CURRENT_GATE
Definition: res_pktccops.c:692
time_t deltimer
Definition: pktccops.h:62
char name[80]
Definition: res_pktccops.c:134
uint32_t handle
Definition: res_pktccops.c:142
#define PKTCCOPS_SCOMMAND_GATE_INFO_ACK
Definition: res_pktccops.c:80
#define COPS_HEADER_SIZE
Definition: res_pktccops.c:67
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
static struct cops_gate * cops_gate_cmd(int cmd, struct cops_cmts *cmts, uint16_t trid, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, struct cops_gate *gate)
Definition: res_pktccops.c:495
#define PKTCCOPS_SCOMMAND_GATE_INFO_ERR
Definition: res_pktccops.c:81
#define PKTCCOPS_SCOMMAND_GATE_DELETE_ACK
Definition: res_pktccops.c:83
#define PKTCCOPS_SCOMMAND_GATE_OPEN
Definition: res_pktccops.c:85
char * msg
Definition: res_pktccops.c:106
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
time_t checked
Definition: pktccops.h:61
#define ast_poll(a, b, c)
Definition: poll-compat.h:88
char * contents
Definition: res_pktccops.c:96
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
#define COPS_OBJECT_HEADER_SIZE
Definition: res_pktccops.c:68
uint16_t trid
Definition: pktccops.h:56
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
static int load_pktccops_config(void)
time_t in_transaction
Definition: pktccops.h:57
unsigned char ctype
Definition: res_pktccops.c:95
uint32_t gateid
Definition: pktccops.h:55
int need_delete
Definition: res_pktccops.c:147
#define PKTCCOPS_SCOMMAND_GATE_SET_ACK
Definition: res_pktccops.c:77
uint16_t length
Definition: res_pktccops.c:93
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int ast_poll_fd_index(struct pollfd *haystack, int nfds, int needle)
Shortcut for conversion of FD_ISSET to poll(2)-based.
Definition: poll-compat.h:128
int(* gate_open)(struct cops_gate *gate)
Definition: pktccops.h:66
static int pktcreload
Definition: res_pktccops.c:162
static uint16_t cops_trid
Definition: res_pktccops.c:90
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_free(a)
Definition: astmm.h:182
#define PKTCCOPS_SCOMMAND_GATE_CLOSE
Definition: res_pktccops.c:86
struct pktcobj * next
Definition: res_pktccops.c:97
struct pktcobj * object
Definition: res_pktccops.c:105
uint32_t keepalive
Definition: res_pktccops.c:140
unsigned char verflag
Definition: res_pktccops.c:101
static void pktccops_unregister_ippools(void)
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
static int cops_getmsg(int sfd, struct copsmsg *recmsg)
Definition: res_pktccops.c:323
char port[80]
Definition: res_pktccops.c:136
uint16_t clienttype
Definition: res_pktccops.c:103
uint32_t mta
Definition: pktccops.h:58
int(* got_dq_gi)(struct cops_gate *gate)
Definition: pktccops.h:64
char host[80]
Definition: res_pktccops.c:135
unsigned char cnum
Definition: res_pktccops.c:94
struct cops_cmts * cmts
Definition: pktccops.h:63

◆ ftoieeef()

static uint32_t ftoieeef ( float  n)
static

Definition at line 175 of file res_pktccops.c.

Referenced by cops_construct_gate().

176 {
177  uint32_t res;
178  memcpy(&res, &n, 4);
179  return htonl(res);
180 }

◆ load_module()

static int load_module ( void  )
static

Definition at line 1463 of file res_pktccops.c.

References ast_cli_register_multiple, AST_LIST_LOCK, AST_LIST_UNLOCK, AST_MODULE_LOAD_DECLINE, load_pktccops_config(), and restart_pktc_thread().

Referenced by reload_module().

1464 {
1465  int res;
1467  res = load_pktccops_config();
1469  if (res == -1) {
1470  return AST_MODULE_LOAD_DECLINE;
1471  }
1474 
1475  return 0;
1476 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
descriptor for a cli entry.
Definition: cli.h:171
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry cli_pktccops[]
static int load_pktccops_config(void)
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int restart_pktc_thread(void)
Definition: res_pktccops.c:993

◆ load_pktccops_config()

static int load_pktccops_config ( void  )
static

Definition at line 1022 of file res_pktccops.c.

References a, ast_calloc, ast_category_browse(), ast_config_destroy(), ast_config_load, ast_copy_string(), AST_LIST_INSERT_HEAD, AST_LIST_TRAVERSE, ast_log, ast_variable_browse(), b, c, cops_ippool::cmts, config, d, DEFAULT_COPS_PORT, gateinfoperiod, gatetimeout, host, cops_cmts::host, cops_cmts::keepalive, keepalive, LOG_WARNING, ast_variable::name, cops_cmts::name, cops_cmts::need_delete, ast_variable::next, NULL, pktccops_add_ippool(), cops_cmts::port, cops_cmts::sfd, cops_ippool::start, cops_cmts::state, cops_ippool::stop, cops_cmts::t1, t1, cops_cmts::t7, t7, cops_cmts::t8, t8, update(), and ast_variable::value.

Referenced by do_pktccops(), and load_module().

1023 {
1024  static char *cfg = "res_pktccops.conf";
1025  struct ast_config *config;
1026  struct ast_variable *v;
1027  struct cops_cmts *cmts;
1028  struct cops_ippool *new_ippool;
1029  const char *host, *cat, *port;
1030  int update;
1031  int res = 0;
1032  uint16_t t1_temp, t7_temp, t8_temp;
1033  uint32_t keepalive_temp;
1034  unsigned int a,b,c,d,e,f,g,h;
1035  struct ast_flags config_flags = {0};
1036 
1037  if (!(config = ast_config_load(cfg, config_flags))) {
1038  ast_log(LOG_WARNING, "Unable to load config file res_pktccops.conf\n");
1039  return -1;
1040  }
1041  for (cat = ast_category_browse(config, NULL); cat; cat = ast_category_browse(config, cat)) {
1042  if (!strcmp(cat, "general")) {
1043  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1044  if (!strcasecmp(v->name, "t1")) {
1045  t1 = atoi(v->value);
1046  } else if (!strcasecmp(v->name, "t7")) {
1047  t7 = atoi(v->value);
1048  } else if (!strcasecmp(v->name, "t8")) {
1049  t8 = atoi(v->value);
1050  } else if (!strcasecmp(v->name, "keepalive")) {
1051  keepalive = atoi(v->value);
1052  } else if (!strcasecmp(v->name, "gateinfoperiod")) {
1053  gateinfoperiod = atoi(v->value);
1054  } else if (!strcasecmp(v->name, "gatetimeout")) {
1055  gatetimeout = atoi(v->value);
1056  } else {
1057  ast_log(LOG_WARNING, "Unkown option %s in general section of res_ptkccops.conf\n", v->name);
1058  }
1059  }
1060  } else {
1061  /* Defaults */
1062  host = NULL;
1063  port = NULL;
1064  t1_temp = t1;
1065  t7_temp = t7;
1066  t8_temp = t8;
1067  keepalive_temp = keepalive;
1068 
1069  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1070  if (!strcasecmp(v->name, "host")) {
1071  host = v->value;
1072  } else if (!strcasecmp(v->name, "port")) {
1073  port = v->value;
1074  } else if (!strcasecmp(v->name, "t1")) {
1075  t1_temp = atoi(v->value);
1076  } else if (!strcasecmp(v->name, "t7")) {
1077  t7_temp = atoi(v->value);
1078  } else if (!strcasecmp(v->name, "t8")) {
1079  t8_temp = atoi(v->value);
1080  } else if (!strcasecmp(v->name, "keepalive")) {
1081  keepalive_temp = atoi(v->value);
1082  } else if (!strcasecmp(v->name, "pool")) {
1083  /* we weill parse it in 2nd round */
1084  } else {
1085  ast_log(LOG_WARNING, "Unkown option %s in res_ptkccops.conf\n", v->name);
1086  }
1087  }
1088 
1089  update = 0;
1090  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1091  if (!strcmp(cmts->name, cat)) {
1092  update = 1;
1093  break;
1094  }
1095 
1096  }
1097  if (!update) {
1098  cmts = ast_calloc(1, sizeof(*cmts));
1099  if (!cmts) {
1100  res = -1;
1101  break;
1102  }
1103  AST_LIST_INSERT_HEAD(&cmts_list, cmts, list);
1104  }
1105  if (cat) {
1106  ast_copy_string(cmts->name, cat, sizeof(cmts->name));
1107  }
1108  if (host) {
1109  ast_copy_string(cmts->host, host, sizeof(cmts->host));
1110  }
1111  if (port) {
1112  ast_copy_string(cmts->port, port, sizeof(cmts->port));
1113  } else {
1114  ast_copy_string(cmts->port, DEFAULT_COPS_PORT, sizeof(cmts->port));
1115  }
1116 
1117  cmts->t1 = t1_temp;
1118  cmts->t7 = t7_temp;
1119  cmts->t8 = t8_temp;
1120  cmts->keepalive = keepalive_temp;
1121  if (!update) {
1122  cmts->state = 0;
1123  cmts->sfd = -1;
1124  }
1125  cmts->need_delete = 0;
1126  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1127  /* parse ipppol when we have cmts ptr */
1128  if (!strcasecmp(v->name, "pool")) {
1129  if (sscanf(v->value, "%3u.%3u.%3u.%3u %3u.%3u.%3u.%3u", &a, &b, &c, &d, &e, &f, &g, &h) == 8) {
1130  new_ippool = ast_calloc(1, sizeof(*new_ippool));
1131  if (!new_ippool) {
1132  res = -1;
1133  break;
1134  }
1135  new_ippool->start = a << 24 | b << 16 | c << 8 | d;
1136  new_ippool->stop = e << 24 | f << 16 | g << 8 | h;
1137  new_ippool->cmts = cmts;
1138  pktccops_add_ippool(new_ippool);
1139  } else {
1140  ast_log(LOG_WARNING, "Invalid ip pool format in res_pktccops.conf\n");
1141  }
1142  }
1143  }
1144  }
1145  }
1146  ast_config_destroy(config);
1147  return res;
1148 }
struct ast_variable * next
static int pktccops_add_ippool(struct cops_ippool *ippool)
char * config
Definition: conf2ael.c:66
static uint32_t keepalive
Definition: res_pktccops.c:160
static int gatetimeout
Definition: res_pktccops.c:164
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition: codec_g726.c:367
static int gateinfoperiod
Definition: res_pktccops.c:163
#define LOG_WARNING
Definition: logger.h:274
static struct test_val d
Structure for variables, used for configurations and for channel variables.
char name[80]
Definition: res_pktccops.c:134
static struct test_val c
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3328
#define NULL
Definition: resample.c:96
static uint16_t t7
Definition: res_pktccops.c:158
uint32_t start
Definition: res_pktccops.c:152
#define ast_log
Definition: astobj2.c:42
#define ast_config_load(filename, flags)
Load a config file.
static char host[256]
Definition: muted.c:77
uint16_t t7
Definition: res_pktccops.c:138
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
static uint16_t t8
Definition: res_pktccops.c:159
int need_delete
Definition: res_pktccops.c:147
uint16_t t1
Definition: res_pktccops.c:137
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct cops_cmts * cmts
Definition: res_pktccops.c:154
Structure used to handle boolean flags.
Definition: utils.h:199
uint32_t keepalive
Definition: res_pktccops.c:140
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static struct test_val b
uint32_t stop
Definition: res_pktccops.c:153
uint16_t t8
Definition: res_pktccops.c:139
#define DEFAULT_COPS_PORT
Definition: res_pktccops.c:65
char port[80]
Definition: res_pktccops.c:136
char host[80]
Definition: res_pktccops.c:135
static uint16_t t1
Definition: res_pktccops.c:157
static struct test_val a

◆ pktccops_add_ippool()

static int pktccops_add_ippool ( struct cops_ippool ippool)
static

Definition at line 1420 of file res_pktccops.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log, ast_cli_entry::list, and LOG_WARNING.

Referenced by load_pktccops_config().

1421 {
1422  if (ippool) {
1424  AST_LIST_INSERT_HEAD(&ippool_list, ippool, list);
1426  return 0;
1427  } else {
1428  ast_log(LOG_WARNING, "Attempted to register NULL ippool?\n");
1429  return -1;
1430  }
1431 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define ast_log
Definition: astobj2.c:42
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710

◆ pktccops_debug()

static char* pktccops_debug ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1383 of file res_pktccops.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, pktccopsdebug, and ast_cli_entry::usage.

1384 {
1385  switch (cmd) {
1386  case CLI_INIT:
1387  e->command = "pktccops set debug {on|off}";
1388  e->usage =
1389  "Usage: pktccops set debug {on|off}\n"
1390  " Turn on/off debuging\n";
1391  return NULL;
1392  case CLI_GENERATE:
1393  return NULL;
1394  }
1395 
1396  if (a->argc != e->args)
1397  return CLI_SHOWUSAGE;
1398  if (!strncasecmp(a->argv[e->args - 1], "on", 2)) {
1399  pktccopsdebug = 1;
1400  ast_cli(a->fd, "PktcCOPS Debugging Enabled\n");
1401  } else if (!strncasecmp(a->argv[e->args - 1], "off", 2)) {
1402  pktccopsdebug = 0;
1403  ast_cli(a->fd, "PktcCOPS Debugging Disabled\n");
1404  } else {
1405  return CLI_SHOWUSAGE;
1406  }
1407  return CLI_SUCCESS;
1408 
1409 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int args
This gets set in ast_cli_register()
Definition: cli.h:185
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
static int pktccopsdebug
Definition: res_pktccops.c:161

◆ pktccops_gatedel()

static char* pktccops_gatedel ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1266 of file res_pktccops.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, cops_gate::cmts, ast_cli_entry::command, cops_gate_cmd(), cops_trid, ast_cli_args::fd, GATE_DEL, cops_gate::gateid, cops_cmts::list, cops_cmts::name, NULL, and ast_cli_entry::usage.

1267 {
1268  int found = 0;
1269  int trid;
1270  uint32_t gateid;
1271  struct cops_gate *gate;
1272  struct cops_cmts *cmts;
1273 
1274  switch (cmd) {
1275  case CLI_INIT:
1276  e->command = "pktccops gatedel";
1277  e->usage =
1278  "Usage: pktccops gatedel <cmts> <gateid>\n"
1279  " Send Gate-Del to cmts.\n";
1280  return NULL;
1281  case CLI_GENERATE:
1282  return NULL;
1283  }
1284 
1285  if (a->argc < 4)
1286  return CLI_SHOWUSAGE;
1287 
1289  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1290  if (!strcmp(cmts->name, a->argv[2])) {
1291  ast_cli(a->fd, "Found cmts: %s\n", cmts->name);
1292  found = 1;
1293  break;
1294  }
1295  }
1297 
1298  if (!found)
1299  return CLI_SHOWUSAGE;
1300 
1301  trid = cops_trid++;
1302  if (!sscanf(a->argv[3], "%x", &gateid)) {
1303  ast_cli(a->fd, "bad gate specification (%s)\n", a->argv[3]);
1304  return CLI_SHOWUSAGE;
1305  }
1306 
1307  found = 0;
1309  AST_LIST_TRAVERSE(&gate_list, gate, list) {
1310  if (gate->gateid == gateid && gate->cmts == cmts) {
1311  found = 1;
1312  break;
1313  }
1314  }
1315 
1316  if (!found) {
1317  ast_cli(a->fd, "gate not found: %s\n", a->argv[3]);
1318  return CLI_SHOWUSAGE;
1319  }
1320 
1322  cops_gate_cmd(GATE_DEL, cmts, trid, 0, 0, 0, 0, 0, 0, gate);
1323  return CLI_SUCCESS;
1324 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
const int argc
Definition: cli.h:160
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:152
char name[80]
Definition: res_pktccops.c:134
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static struct cops_gate * cops_gate_cmd(int cmd, struct cops_cmts *cmts, uint16_t trid, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, struct cops_gate *gate)
Definition: res_pktccops.c:495
struct cops_cmts::@489 list
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
uint32_t gateid
Definition: pktccops.h:55
#define CLI_SHOWUSAGE
Definition: cli.h:45
static uint16_t cops_trid
Definition: res_pktccops.c:90
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
struct cops_cmts * cmts
Definition: pktccops.h:63

◆ pktccops_gateset()

static char* pktccops_gateset ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1326 of file res_pktccops.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, cops_gate_cmd(), cops_trid, ast_cli_args::fd, GATE_SET, cops_cmts::list, cops_cmts::name, NULL, and ast_cli_entry::usage.

1327 {
1328  int foundcmts = 0;
1329  int trid;
1330  unsigned int an,bn,cn,dn;
1331  uint32_t mta, ssip;
1332  struct cops_cmts *cmts;
1333 
1334  switch (cmd) {
1335  case CLI_INIT:
1336  e->command = "pktccops gateset";
1337  e->usage =
1338  "Usage: pktccops gateset <cmts> <mta> <acctcount> <bitrate> <packet size> <switch ip> <switch port>\n"
1339  " Send Gate-Set to cmts.\n";
1340  return NULL;
1341  case CLI_GENERATE:
1342  return NULL;
1343  }
1344 
1345  if (a->argc < 9)
1346  return CLI_SHOWUSAGE;
1347 
1348  if (!strcmp(a->argv[2], "null")) {
1349  cmts = NULL;
1350  } else {
1352  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1353  if (!strcmp(cmts->name, a->argv[2])) {
1354  ast_cli(a->fd, "Found cmts: %s\n", cmts->name);
1355  foundcmts = 1;
1356  break;
1357  }
1358  }
1360  if (!foundcmts) {
1361  ast_cli(a->fd, "CMTS not found: %s\n", a->argv[2]);
1362  return CLI_SHOWUSAGE;
1363  }
1364  }
1365 
1366  trid = cops_trid++;
1367  if (sscanf(a->argv[3], "%3u.%3u.%3u.%3u", &an, &bn, &cn, &dn) != 4) {
1368  ast_cli(a->fd, "MTA specification (%s) does not look like an ipaddr\n", a->argv[3]);
1369  return CLI_SHOWUSAGE;
1370  }
1371  mta = an << 24 | bn << 16 | cn << 8 | dn;
1372 
1373  if (sscanf(a->argv[7], "%3u.%3u.%3u.%3u", &an, &bn, &cn, &dn) != 4) {
1374  ast_cli(a->fd, "SSIP specification (%s) does not look like an ipaddr\n", a->argv[7]);
1375  return CLI_SHOWUSAGE;
1376  }
1377  ssip = an << 24 | bn << 16 | cn << 8 | dn;
1378 
1379  cops_gate_cmd(GATE_SET, cmts, trid, mta, atoi(a->argv[4]), atof(a->argv[5]), atoi(a->argv[6]), ssip, atoi(a->argv[8]), NULL);
1380  return CLI_SUCCESS;
1381 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
const int argc
Definition: cli.h:160
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:152
char name[80]
Definition: res_pktccops.c:134
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static struct cops_gate * cops_gate_cmd(int cmd, struct cops_cmts *cmts, uint16_t trid, uint32_t mta, uint32_t actcount, float bitrate, uint32_t psize, uint32_t ssip, uint16_t ssport, struct cops_gate *gate)
Definition: res_pktccops.c:495
struct cops_cmts::@489 list
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
static uint16_t cops_trid
Definition: res_pktccops.c:90
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ pktccops_show_cmtses()

static char* pktccops_show_cmtses ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1150 of file res_pktccops.c.

References ast_cli(), ast_copy_string(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, cops_cmts::host, cops_cmts::katimer, cops_cmts::list, cops_cmts::name, NULL, cops_cmts::port, cops_cmts::state, and ast_cli_entry::usage.

1151 {
1152  struct cops_cmts *cmts;
1153  char statedesc[16];
1154  int katimer;
1155 
1156  switch(cmd) {
1157  case CLI_INIT:
1158  e->command = "pktccops show cmtses";
1159  e->usage =
1160  "Usage: pktccops show cmtses\n"
1161  " List PacketCable COPS CMTSes.\n";
1162 
1163  return NULL;
1164  case CLI_GENERATE:
1165  return NULL;
1166  }
1167 
1168  ast_cli(a->fd, "%-16s %-24s %-12s %7s\n", "Name ", "Host ", "Status ", "KA timer ");
1169  ast_cli(a->fd, "%-16s %-24s %-12s %7s\n", "------------", "--------------------", "----------", "-----------");
1171  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1172  katimer = -1;
1173  if (cmts->state == 2) {
1174  ast_copy_string(statedesc, "Connected", sizeof(statedesc));
1175  katimer = (int) (time(NULL) - cmts->katimer);
1176  } else if (cmts->state == 1) {
1177  ast_copy_string(statedesc, "Connecting", sizeof(statedesc));
1178  } else {
1179  ast_copy_string(statedesc, "N/A", sizeof(statedesc));
1180  }
1181  ast_cli(a->fd, "%-16s %-15s:%-8s %-12s %-7d\n", cmts->name, cmts->host, cmts->port, statedesc, katimer);
1182  }
1184  return CLI_SUCCESS;
1185 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
time_t katimer
Definition: res_pktccops.c:145
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:152
char name[80]
Definition: res_pktccops.c:134
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
struct cops_cmts::@489 list
const int fd
Definition: cli.h:159
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
char port[80]
Definition: res_pktccops.c:136
char host[80]
Definition: res_pktccops.c:135

◆ pktccops_show_gates()

static char* pktccops_show_gates ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1187 of file res_pktccops.c.

References cops_gate::allocated, ast_cli(), ast_copy_string(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, cops_gate::checked, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, cops_gate::cmts, ast_cli_entry::command, ast_cli_args::fd, GATE_ALLOC_FAILED, GATE_ALLOC_PROGRESS, GATE_ALLOCATED, GATE_CLOSED, GATE_CLOSED_ERR, GATE_DELETED, GATE_OPEN, cops_gate::gateid, cops_gate::in_transaction, cops_gate::mta, cops_cmts::name, NULL, cops_gate::state, and ast_cli_entry::usage.

1188 {
1189  struct cops_gate *gate;
1190  char state_desc[16];
1191 
1192  switch(cmd) {
1193  case CLI_INIT:
1194  e->command = "pktccops show gates";
1195  e->usage =
1196  "Usage: pktccops show gates\n"
1197  " List PacketCable COPS GATEs.\n";
1198 
1199  return NULL;
1200  case CLI_GENERATE:
1201  return NULL;
1202  }
1203 
1204  ast_cli(a->fd, "%-16s %-12s %-12s %-10s %-10s %-10s\n" ,"CMTS", "Gate-Id","MTA", "Status", "AllocTime", "CheckTime");
1205  ast_cli(a->fd, "%-16s %-12s %-12s %-10s %-10s %-10s\n" ,"--------------" ,"----------", "----------", "--------", "--------", "--------\n");
1208  AST_LIST_TRAVERSE(&gate_list, gate, list) {
1209  if (gate->state == GATE_ALLOC_FAILED) {
1210  ast_copy_string(state_desc, "Failed", sizeof(state_desc));
1211  } else if (gate->state == GATE_ALLOC_PROGRESS) {
1212  ast_copy_string(state_desc, "In Progress", sizeof(state_desc));
1213  } else if (gate->state == GATE_ALLOCATED) {
1214  ast_copy_string(state_desc, "Allocated", sizeof(state_desc));
1215  } else if (gate->state == GATE_CLOSED) {
1216  ast_copy_string(state_desc, "Closed", sizeof(state_desc));
1217  } else if (gate->state == GATE_CLOSED_ERR) {
1218  ast_copy_string(state_desc, "ClosedErr", sizeof(state_desc));
1219  } else if (gate->state == GATE_OPEN) {
1220  ast_copy_string(state_desc, "Open", sizeof(state_desc));
1221  } else if (gate->state == GATE_DELETED) {
1222  ast_copy_string(state_desc, "Deleted", sizeof(state_desc));
1223  } else {
1224  ast_copy_string(state_desc, "N/A", sizeof(state_desc));
1225  }
1226 
1227  ast_cli(a->fd, "%-16s 0x%.8x 0x%08x %-10s %10i %10i %u\n", (gate->cmts) ? gate->cmts->name : "null" , gate->gateid, gate->mta,
1228  state_desc, (int) (time(NULL) - gate->allocated), (gate->checked) ? (int) (time(NULL) - gate->checked) : 0, (unsigned int) gate->in_transaction);
1229  }
1232  return CLI_SUCCESS;
1233 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
int state
Definition: pktccops.h:59
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:152
char name[80]
Definition: res_pktccops.c:134
time_t allocated
Definition: pktccops.h:60
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
time_t checked
Definition: pktccops.h:61
time_t in_transaction
Definition: pktccops.h:57
uint32_t gateid
Definition: pktccops.h:55
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
uint32_t mta
Definition: pktccops.h:58
struct cops_cmts * cmts
Definition: pktccops.h:63

◆ pktccops_show_pools()

static char* pktccops_show_pools ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1235 of file res_pktccops.c.

References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, cops_ippool::cmts, ast_cli_entry::command, ast_cli_args::fd, cops_ippool::list, cops_cmts::name, NULL, cops_ippool::start, cops_ippool::stop, stop, and ast_cli_entry::usage.

1236 {
1237  struct cops_ippool *ippool;
1238  char start[32];
1239  char stop[32];
1240 
1241  switch(cmd) {
1242  case CLI_INIT:
1243  e->command = "pktccops show pools";
1244  e->usage =
1245  "Usage: pktccops show pools\n"
1246  " List PacketCable COPS ip pools of MTAs.\n";
1247 
1248  return NULL;
1249  case CLI_GENERATE:
1250  return NULL;
1251  }
1252 
1253  ast_cli(a->fd, "%-16s %-18s %-7s\n", "Start ", "Stop ", "CMTS ");
1254  ast_cli(a->fd, "%-16s %-18s %-7s\n", "----------", "----------", "--------");
1256  AST_LIST_TRAVERSE(&ippool_list, ippool, list) {
1257  snprintf(start, sizeof(start), "%3u.%3u.%3u.%3u", ippool->start >> 24, (ippool->start >> 16) & 0x000000ff, (ippool->start >> 8) & 0x000000ff, ippool->start & 0x000000ff);
1258 
1259  snprintf(stop, sizeof(stop), "%3u.%3u.%3u.%3u", ippool->stop >> 24, (ippool->stop >> 16) & 0x000000ff, (ippool->stop >> 8) & 0x000000ff, ippool->stop & 0x000000ff);
1260  ast_cli(a->fd, "%-16s %-18s %-16s\n", start, stop, ippool->cmts->name);
1261  }
1263  return CLI_SUCCESS;
1264 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
struct cops_ippool::@490 list
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:152
unsigned int stop
Definition: app_meetme.c:1096
char name[80]
Definition: res_pktccops.c:134
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
uint32_t start
Definition: res_pktccops.c:152
const int fd
Definition: cli.h:159
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:186
struct cops_cmts * cmts
Definition: res_pktccops.c:154
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
uint32_t stop
Definition: res_pktccops.c:153

◆ pktccops_unregister_cmtses()

static void pktccops_unregister_cmtses ( void  )
static

Definition at line 1433 of file res_pktccops.c.

References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, and cops_cmts::sfd.

Referenced by unload_module().

1434 {
1435  struct cops_cmts *cmts;
1436  struct cops_gate *gate;
1438  while ((cmts = AST_LIST_REMOVE_HEAD(&cmts_list, list))) {
1439  if (cmts->sfd > 0) {
1440  close(cmts->sfd);
1441  }
1442  ast_free(cmts);
1443  }
1445 
1447  while ((gate = AST_LIST_REMOVE_HEAD(&gate_list, list))) {
1448  ast_free(gate);
1449  }
1451 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define ast_free(a)
Definition: astmm.h:182

◆ pktccops_unregister_ippools()

static void pktccops_unregister_ippools ( void  )
static

Definition at line 1453 of file res_pktccops.c.

References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, and cops_ippool::list.

Referenced by do_pktccops(), and unload_module().

1454 {
1455  struct cops_ippool *ippool;
1457  while ((ippool = AST_LIST_REMOVE_HEAD(&ippool_list, list))) {
1458  ast_free(ippool);
1459  }
1461 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
struct cops_ippool::@490 list
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define ast_free(a)
Definition: astmm.h:182

◆ reload_module()

static int reload_module ( void  )
static

Definition at line 1500 of file res_pktccops.c.

References ast_log, AST_MODFLAG_GLOBAL_SYMBOLS, AST_MODULE_INFO(), AST_MODULE_SUPPORT_EXTENDED, ASTERISK_GPL_KEY, load_module(), LOG_NOTICE, pktcreload, reload(), and unload_module().

1501 {
1502  /* Prohibit unloading */
1503  if (pktcreload) {
1504  ast_log(LOG_NOTICE, "Previous reload in progress, please wait!\n");
1505  return -1;
1506  }
1507  pktcreload = 1;
1508  return 0;
1509 }
#define ast_log
Definition: astobj2.c:42
static int pktcreload
Definition: res_pktccops.c:162
#define LOG_NOTICE
Definition: logger.h:263

◆ restart_pktc_thread()

static int restart_pktc_thread ( void  )
static

Definition at line 993 of file res_pktccops.c.

References ast_log, ast_mutex_lock, ast_mutex_unlock, ast_pthread_create_background, AST_PTHREADT_NULL, AST_PTHREADT_STOP, do_pktccops(), LOG_ERROR, LOG_WARNING, NULL, pktccops_lock, and pktccops_thread.

Referenced by load_module().

994 {
996  return 0;
997  }
999  ast_log(LOG_WARNING, "Unable to lock pktccops\n");
1000  return -1;
1001  }
1002  if (pktccops_thread == pthread_self()) {
1004  ast_log(LOG_WARNING, "Cannot kill myself\n");
1005  return -1;
1006  }
1008  /* Wake up the thread */
1009  pthread_kill(pktccops_thread, SIGURG);
1010  } else {
1011  /* Start a new monitor */
1014  ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
1015  return -1;
1016  }
1017  }
1019  return 0;
1020 }
static ast_mutex_t pktccops_lock
Definition: res_pktccops.c:88
static pthread_t pktccops_thread
Definition: res_pktccops.c:89
#define LOG_WARNING
Definition: logger.h:274
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:567
#define ast_log
Definition: astobj2.c:42
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define LOG_ERROR
Definition: logger.h:285
static void * do_pktccops(void *data)
Definition: res_pktccops.c:699
#define AST_PTHREADT_STOP
Definition: lock.h:67
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 1478 of file res_pktccops.c.

References ast_cli_unregister_multiple(), ast_log, ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, AST_PTHREADT_STOP, LOG_ERROR, NULL, pktccops_lock, pktccops_thread, pktccops_unregister_cmtses(), and pktccops_unregister_ippools().

Referenced by reload_module().

1479 {
1480  if (!ast_mutex_lock(&pktccops_lock)) {
1482  pthread_cancel(pktccops_thread);
1483  pthread_kill(pktccops_thread, SIGURG);
1484  pthread_join(pktccops_thread, NULL);
1485  }
1488  } else {
1489  ast_log(LOG_ERROR, "Unable to lock the pktccops_thread\n");
1490  return -1;
1491  }
1492 
1497  return 0;
1498 }
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static ast_mutex_t pktccops_lock
Definition: res_pktccops.c:88
static pthread_t pktccops_thread
Definition: res_pktccops.c:89
descriptor for a cli entry.
Definition: cli.h:171
static struct ast_cli_entry cli_pktccops[]
#define ast_mutex_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define LOG_ERROR
Definition: logger.h:285
#define AST_PTHREADT_STOP
Definition: lock.h:67
static void pktccops_unregister_cmtses(void)
static void pktccops_unregister_ippools(void)
#define ast_mutex_unlock(a)
Definition: lock.h:188

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS , .description = "PktcCOPS manager for MGCP" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload_module, }
static

Definition at line 1516 of file res_pktccops.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 1516 of file res_pktccops.c.

◆ cli_pktccops

struct ast_cli_entry cli_pktccops[]
static

Definition at line 1411 of file res_pktccops.c.

◆ cmts_list

struct cmts_list cmts_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }

◆ cops_trid

uint16_t cops_trid = 0
static

◆ gate_list

struct gate_list gate_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }

◆ gateinfoperiod

int gateinfoperiod = 60
static

Definition at line 163 of file res_pktccops.c.

Referenced by do_pktccops(), and load_pktccops_config().

◆ gatetimeout

int gatetimeout = 150
static

Definition at line 164 of file res_pktccops.c.

Referenced by do_pktccops(), and load_pktccops_config().

◆ ippool_list

struct ippool_list ippool_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }

◆ keepalive

uint32_t keepalive = 60
static

◆ pktccops_lock

ast_mutex_t pktccops_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
static

Definition at line 88 of file res_pktccops.c.

Referenced by restart_pktc_thread(), and unload_module().

◆ pktccops_thread

pthread_t pktccops_thread = AST_PTHREADT_NULL
static

Definition at line 89 of file res_pktccops.c.

Referenced by restart_pktc_thread(), and unload_module().

◆ pktccopsdebug

int pktccopsdebug = 0
static

Definition at line 161 of file res_pktccops.c.

Referenced by cops_gate_cmd(), and pktccops_debug().

◆ pktcreload

int pktcreload = 0
static

Definition at line 162 of file res_pktccops.c.

Referenced by ast_pktccops_gate_alloc(), do_pktccops(), and reload_module().

◆ t1

uint16_t t1 = 250
static

◆ t7

uint16_t t7 = 200
static

Definition at line 158 of file res_pktccops.c.

Referenced by load_pktccops_config().

◆ t8

uint16_t t8 = 300
static

Definition at line 159 of file res_pktccops.c.

Referenced by load_pktccops_config().