Wed Jan 8 2020 09:50:19

Asterisk developer's documentation


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"

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 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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload_module, }
 
static 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 } , }
 
static uint16_t cops_trid = 0
 
struct gate_list gate_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } , }
 
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 } , }
 
static uint32_t keepalive = 60
 
static ast_mutex_t pktccops_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
 
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

#define AST_API_MODULE

Definition at line 64 of file res_pktccops.c.

#define COPS_HEADER_SIZE   8

Definition at line 69 of file res_pktccops.c.

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

#define COPS_OBJECT_HEADER_SIZE   4

Definition at line 70 of file res_pktccops.c.

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

#define DEFAULT_COPS_PORT   "2126"

Definition at line 67 of file res_pktccops.c.

Referenced by load_pktccops_config().

#define GATE_INFO_OBJ_SIZE   24

Definition at line 73 of file res_pktccops.c.

Referenced by cops_gate_cmd().

#define GATE_SET_OBJ_SIZE   144

Definition at line 71 of file res_pktccops.c.

Referenced by cops_gate_cmd().

#define GATEID_OBJ_SIZE   8

Definition at line 72 of file res_pktccops.c.

Referenced by cops_gate_cmd().

#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:554
#define ast_free(a)
Definition: astmm.h:97
if(yyss+yystacksize-1<=yyssp)
Definition: ast_expr2.c:1874

Definition at line 695 of file res_pktccops.c.

Referenced by do_pktccops().

#define PKTCCOPS_SCOMMAND_GATE_ALLOC   1

Definition at line 75 of file res_pktccops.c.

#define PKTCCOPS_SCOMMAND_GATE_ALLOC_ACK   2

Definition at line 76 of file res_pktccops.c.

#define PKTCCOPS_SCOMMAND_GATE_ALLOC_ERR   3

Definition at line 77 of file res_pktccops.c.

#define PKTCCOPS_SCOMMAND_GATE_CLOSE   14

Definition at line 88 of file res_pktccops.c.

Referenced by do_pktccops().

#define PKTCCOPS_SCOMMAND_GATE_DELETE   10

Definition at line 84 of file res_pktccops.c.

Referenced by cops_construct_gate().

#define PKTCCOPS_SCOMMAND_GATE_DELETE_ACK   11

Definition at line 85 of file res_pktccops.c.

Referenced by do_pktccops().

#define PKTCCOPS_SCOMMAND_GATE_DELETE_ERR   12

Definition at line 86 of file res_pktccops.c.

#define PKTCCOPS_SCOMMAND_GATE_INFO   7

Definition at line 81 of file res_pktccops.c.

Referenced by cops_construct_gate().

#define PKTCCOPS_SCOMMAND_GATE_INFO_ACK   8

Definition at line 82 of file res_pktccops.c.

Referenced by do_pktccops().

#define PKTCCOPS_SCOMMAND_GATE_INFO_ERR   9

Definition at line 83 of file res_pktccops.c.

Referenced by do_pktccops().

#define PKTCCOPS_SCOMMAND_GATE_OPEN   13

Definition at line 87 of file res_pktccops.c.

Referenced by do_pktccops().

#define PKTCCOPS_SCOMMAND_GATE_SET   4

Definition at line 78 of file res_pktccops.c.

Referenced by cops_construct_gate().

#define PKTCCOPS_SCOMMAND_GATE_SET_ACK   5

Definition at line 79 of file res_pktccops.c.

Referenced by do_pktccops().

#define PKTCCOPS_SCOMMAND_GATE_SET_ERR   6

Definition at line 80 of file res_pktccops.c.

Referenced by do_pktccops().

#define SENDFLAGS   MSG_NOSIGNAL | MSG_DONTWAIT

Referenced by cops_sendmsg().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 1517 of file res_pktccops.c.

static void __unreg_module ( void  )
static

Definition at line 1517 of file res_pktccops.c.

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 470 of file res_pktccops.c.

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

Referenced by mgcp_alloc_pktcgate(), and mgcp_hangup().

475 {
476  while (pktcreload) {
477  sched_yield();
478  }
479 
480  if (cmd == GATE_SET_HAVE_GATEID && gate) {
481  ast_debug(3, "------- gate modify gateid 0x%x ssip: 0x%x\n", gate->gateid, ssip);
482  /* TODO implement it */
483  ast_log(LOG_WARNING, "Modify GateID not implemented\n");
484  }
485 
486  if ((gate = cops_gate_cmd(cmd, NULL, cops_trid++, mta, actcount, bitrate, psize, ssip, ssport, gate))) {
487  ast_debug(3, "COPS: Allocating gate for mta: 0x%x\n", mta);
488  gate->got_dq_gi = got_dq_gi;
489  gate->gate_remove = gate_remove;
490  return(gate);
491  } else {
492  ast_debug(3, "COPS: Couldn't allocate gate for mta: 0x%x\n", mta);
493  return NULL;
494  }
495 }
int(* gate_remove)(struct cops_gate *gate)
Definition: pktccops.h:65
#define LOG_WARNING
Definition: logger.h:144
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:497
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
uint32_t gateid
Definition: pktccops.h:55
static int pktcreload
Definition: res_pktccops.c:164
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static uint16_t cops_trid
Definition: res_pktccops.c:92
int(* got_dq_gi)(struct cops_gate *gate)
Definition: pktccops.h:64
static int cops_connect ( char *  host,
char *  port 
)
static

Definition at line 651 of file res_pktccops.c.

References ast_debug, ast_log(), and LOG_WARNING.

Referenced by do_pktccops().

652 {
653  int s, sfd = -1, flags;
654  struct addrinfo hints;
655  struct addrinfo *rp;
656  struct addrinfo *result;
657 #ifdef HAVE_SO_NOSIGPIPE
658  int trueval = 1;
659 #endif
660 
661  memset(&hints, 0, sizeof(struct addrinfo));
662 
663  hints.ai_family = AF_UNSPEC;
664  hints.ai_socktype = SOCK_STREAM;
665  hints.ai_flags = 0;
666  hints.ai_protocol = 0;
667 
668  s = getaddrinfo(host, port, &hints, &result);
669  if (s != 0) {
670  ast_log(LOG_WARNING, "COPS: getaddrinfo: %s\n", gai_strerror(s));
671  return -1;
672  }
673 
674  for (rp = result; rp != NULL; rp = rp->ai_next) {
675  sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
676  if (sfd == -1) {
677  ast_log(LOG_WARNING, "Failed socket\n");
678  }
679  flags = fcntl(sfd, F_GETFL);
680  fcntl(sfd, F_SETFL, flags | O_NONBLOCK);
681 #ifdef HAVE_SO_NOSIGPIPE
682  setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, &trueval, sizeof(trueval));
683 #endif
684  connect(sfd, rp->ai_addr, rp->ai_addrlen);
685  if (sfd == -1) {
686  ast_log(LOG_WARNING, "Failed connect\n");
687  }
688  }
689  freeaddrinfo(result);
690 
691  ast_debug(3, "Connecting to cmts: %s:%s\n", host, port);
692  return(sfd);
693 }
#define LOG_WARNING
Definition: logger.h:144
static struct ao2_container * hints
Definition: pbx.c:1314
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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 223 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().

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

Definition at line 184 of file res_pktccops.c.

References gatespec::b, gatespec::diffserv, gatespec::direction, gatespec::dstip, gatespec::dstp, gatespec::flags, gatespec::m, gatespec::mm, 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().

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

Definition at line 455 of file res_pktccops.c.

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

Referenced by cops_gate_cmd(), and do_pktccops().

456 {
457  struct pktcobj *pnext;
458  free(p->msg);
459  p->msg = NULL;
460  while (p->object != NULL) {
461  pnext = p->object->next;
462  ast_free(p->object->contents);
463  p->object->contents = NULL;
464  ast_free(p->object);
465  p->object = pnext;
466  }
467  p->object = NULL;
468 }
char * msg
Definition: res_pktccops.c:108
char * contents
Definition: res_pktccops.c:98
#define free(a)
Definition: astmm.h:94
#define ast_free(a)
Definition: astmm.h:97
struct pktcobj * next
Definition: res_pktccops.c:99
struct pktcobj * object
Definition: res_pktccops.c:107
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 497 of file res_pktccops.c.

References ast_calloc, ast_debug, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), 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, free, 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, LOG_WARNING, malloc, copsmsg::msg, cops_cmts::name, pktcobj::next, 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().

500 {
501  struct copsmsg *gateset;
502  struct cops_gate *new;
503  struct cops_ippool *ippool;
504 
505  if (cmd == GATE_DEL) {
506  if (gate == NULL) {
507  return NULL;
508  } else {
509  cmts = gate->cmts;
510  }
511  }
512 
513  if (!cmts) {
515  AST_LIST_TRAVERSE(&ippool_list, ippool, list) {
516  if (mta >= ippool->start && mta <= ippool->stop) {
517  cmts = ippool->cmts;
518  break;
519  }
520  }
522  if (!cmts) {
523  ast_log(LOG_WARNING, "COPS: couldn't find cmts for mta: 0x%x\n", mta);
524  return NULL;
525  }
526  if (cmts->sfd < 0) {
527  ast_log(LOG_WARNING, "CMTS: %s not connected\n", cmts->name);
528  return NULL;
529  }
530  }
531 
532  if (cmd == GATE_SET) {
533  new = ast_calloc(1, sizeof(*new));
534  new->gateid = 0;
535  new->trid = trid;
536  new->mta = mta;
537  new->state = GATE_ALLOC_PROGRESS;
538  new->checked = time(NULL);
539  new->allocated = time(NULL);
540  new->cmts = cmts;
541  new->got_dq_gi = NULL;
542  new->gate_remove = NULL;
543  new->gate_open = NULL;
544  new->tech_pvt = NULL;
545  new->deltimer = 0;
549  gate = new;
550  } else {
551  if (gate) {
552  gate->trid = trid;
553  }
554  }
555 
556  gate->in_transaction = time(NULL);
557 
558  if (!(gateset = malloc(sizeof(struct copsmsg)))) {
559  free(gateset);
560  return NULL;
561  }
562  gateset->msg = NULL;
563  gateset->verflag = 0x10;
564  gateset->opcode = 2; /* Decision */
565  gateset->clienttype = 0x8008; /* =PacketCable */
566 
567  /* Handle object */
568  gateset->object = malloc(sizeof(struct pktcobj));
569  if (!gateset->object) {
570  cops_freemsg(gateset);
571  free(gateset);
572  return NULL;
573  }
574  gateset->object->length = COPS_OBJECT_HEADER_SIZE + 4;
575  gateset->object->cnum = 1; /* Handle */
576  gateset->object->ctype = 1; /* client */
577  if (!(gateset->object->contents = malloc(sizeof(uint32_t)))) {
578  cops_freemsg(gateset);
579  free(gateset);
580  return NULL;
581  }
582  *((uint32_t *) gateset->object->contents) = htonl(cmts->handle);
583 
584  /* Context Object */
585  if (!(gateset->object->next = malloc(sizeof(struct pktcobj)))) {
586  cops_freemsg(gateset);
587  free(gateset);
588  return NULL;
589  }
590  gateset->object->next->length = COPS_OBJECT_HEADER_SIZE + 4;
591  gateset->object->next->cnum = 2; /* Context */
592  gateset->object->next->ctype = 1; /* Context */
593  if (!(gateset->object->next->contents = malloc(sizeof(uint32_t)))) {
594  cops_freemsg(gateset);
595  free(gateset);
596  return NULL;
597  }
598  *((uint32_t *) gateset->object->next->contents) = htonl(0x00080000); /* R-Type = 8 configuration request, M-Type = 0 */
599 
600  /* Decision Object: Flags */
601  if (!(gateset->object->next->next = malloc(sizeof(struct pktcobj)))) {
602  cops_freemsg(gateset);
603  free(gateset);
604  return NULL;
605  }
606  gateset->object->next->next->length = COPS_OBJECT_HEADER_SIZE + 4;
607  gateset->object->next->next->cnum = 6; /* Decision */
608  gateset->object->next->next->ctype = 1; /* Flags */
609  if (!(gateset->object->next->next->contents = malloc(sizeof(uint32_t)))) {
610  cops_freemsg(gateset);
611  free(gateset);
612  return NULL;
613  }
614  *((uint32_t *) gateset->object->next->next->contents) = htonl(0x00010001); /* Install, Trigger Error */
615 
616  /* Decision Object: Data */
617  if (!(gateset->object->next->next->next = malloc(sizeof(struct pktcobj)))) {
618  cops_freemsg(gateset);
619  free(gateset);
620  return NULL;
621  }
623  gateset->object->next->next->next->cnum = 6; /* Decision */
624  gateset->object->next->next->next->ctype = 4; /* Decision Data */
626  if (!gateset->object->next->next->next->contents) {
627  cops_freemsg(gateset);
628  free(gateset);
629  return NULL;
630  }
631  gateset->object->next->next->next->next = NULL;
632 
633  gateset->length = COPS_HEADER_SIZE + gateset->object->length + gateset->object->next->length + gateset->object->next->next->length + gateset->object->next->next->next->length;
634 
635  if ((cmd == GATE_INFO || cmd == GATE_SET_HAVE_GATEID || cmd == GATE_DEL) && gate) {
636  ast_debug(1, "Construct gate with gateid: 0x%x\n", gate->gateid);
637  cops_construct_gate(cmd, gateset->object->next->next->next->contents, trid, mta, actcount, bitrate, psize, ssip, ssport, gate->gateid, cmts);
638  } else {
639  ast_debug(1, "Construct new gate\n");
640  cops_construct_gate(cmd, gateset->object->next->next->next->contents, trid, mta, actcount, bitrate, psize, ssip, ssport, 0, cmts);
641  }
642  if (pktccopsdebug) {
643  ast_debug(3, "send cmd\n");
644  }
645  cops_sendmsg(cmts->sfd, gateset);
646  cops_freemsg(gateset);
647  free(gateset);
648  return gate;
649 }
uint32_t length
Definition: res_pktccops.c:106
#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:390
unsigned char opcode
Definition: res_pktccops.c:104
#define malloc(a)
Definition: astmm.h:88
static void cops_freemsg(struct copsmsg *p)
Definition: res_pktccops.c:455
#define LOG_WARNING
Definition: logger.h:144
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
unsigned int stop
Definition: app_meetme.c:969
char name[80]
Definition: res_pktccops.c:136
uint32_t handle
Definition: res_pktccops.c:144
#define COPS_HEADER_SIZE
Definition: res_pktccops.c:69
char * msg
Definition: res_pktccops.c:108
uint32_t start
Definition: res_pktccops.c:154
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define GATE_SET_OBJ_SIZE
Definition: res_pktccops.c:71
char * contents
Definition: res_pktccops.c:98
#define COPS_OBJECT_HEADER_SIZE
Definition: res_pktccops.c:70
uint16_t trid
Definition: pktccops.h:56
#define GATE_INFO_OBJ_SIZE
Definition: res_pktccops.c:73
time_t in_transaction
Definition: pktccops.h:57
unsigned char ctype
Definition: res_pktccops.c:97
uint32_t gateid
Definition: pktccops.h:55
#define free(a)
Definition: astmm.h:94
uint16_t length
Definition: res_pktccops.c:95
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#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:696
struct cops_ippool::@345 list
struct cops_cmts * cmts
Definition: res_pktccops.c:156
struct pktcobj * next
Definition: res_pktccops.c:99
struct pktcobj * object
Definition: res_pktccops.c:107
#define GATEID_OBJ_SIZE
Definition: res_pktccops.c:72
#define ast_calloc(a, b)
Definition: astmm.h:82
unsigned char verflag
Definition: res_pktccops.c:103
static int pktccopsdebug
Definition: res_pktccops.c:163
uint16_t clienttype
Definition: res_pktccops.c:105
unsigned char cnum
Definition: res_pktccops.c:96
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:223
struct cops_cmts * cmts
Definition: pktccops.h:63
static int cops_getmsg ( int  sfd,
struct copsmsg recmsg 
)
static

Definition at line 325 of file res_pktccops.c.

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

Referenced by do_pktccops().

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

Definition at line 390 of file res_pktccops.c.

References ast_debug, ast_log(), copsmsg::clienttype, pktcobj::cnum, pktcobj::contents, COPS_HEADER_SIZE, pktcobj::ctype, errno, free, pktcobj::length, copsmsg::length, LOG_WARNING, malloc, copsmsg::msg, pktcobj::next, copsmsg::object, copsmsg::opcode, SENDFLAGS, and copsmsg::verflag.

Referenced by cops_gate_cmd(), and do_pktccops().

391 {
392  char *buf;
393  int bufpos;
394  struct pktcobj *pobject;
395 
396  if (sfd < 0) {
397  return -1;
398  }
399 
400  ast_debug(3, "COPS: sending opcode: %i len: %u\n", sendmsg->opcode, sendmsg->length);
401  if (sendmsg->length < COPS_HEADER_SIZE) {
402  ast_log(LOG_WARNING, "COPS: invalid msg size!!!\n");
403  return -1;
404  }
405  if (!(buf = malloc((size_t) sendmsg->length))) {
406  return -1;
407  }
408  *buf = sendmsg->verflag ;
409  *(buf + 1) = sendmsg->opcode;
410  *((uint16_t *)(buf + 2)) = htons(sendmsg->clienttype);
411  *((uint32_t *)(buf + 4)) = htonl(sendmsg->length);
412 
413  if (sendmsg->msg != NULL) {
414  memcpy(buf + COPS_HEADER_SIZE, sendmsg->msg, sendmsg->length - COPS_HEADER_SIZE);
415  } else if (sendmsg->object != NULL) {
416  bufpos = 8;
417  pobject = sendmsg->object;
418  while(pobject != NULL) {
419  ast_debug(3, "COPS: Sending Object : cnum: %i ctype %i len: %i\n", pobject->cnum, pobject->ctype, pobject->length);
420  if (sendmsg->length < bufpos + pobject->length) {
421  ast_log(LOG_WARNING, "COPS: Invalid msg size len: %u objectlen: %i\n", sendmsg->length, pobject->length);
422  free(buf);
423  return -1;
424  }
425  *(uint16_t *) (buf + bufpos) = htons(pobject->length);
426  *(buf + bufpos + 2) = pobject->cnum;
427  *(buf + bufpos + 3) = pobject->ctype;
428  if (sendmsg->length < pobject->length + bufpos) {
429  ast_log(LOG_WARNING, "COPS: Error sum of object len more the msg len %u < %i\n", sendmsg->length, pobject->length + bufpos);
430  free(buf);
431  return -1;
432  }
433  memcpy((buf + bufpos + 4), pobject->contents, pobject->length - 4);
434  bufpos += pobject->length;
435  pobject = pobject->next;
436  }
437  }
438 
439  errno = 0;
440 #ifdef HAVE_MSG_NOSIGNAL
441 #define SENDFLAGS MSG_NOSIGNAL | MSG_DONTWAIT
442 #else
443 #define SENDFLAGS MSG_DONTWAIT
444 #endif
445  if (send(sfd, buf, sendmsg->length, SENDFLAGS) == -1) {
446  ast_log(LOG_WARNING, "COPS: Send failed errno=%i\n", errno);
447  free(buf);
448  return -2;
449  }
450 #undef SENDFLAGS
451  free(buf);
452  return 0;
453 }
uint32_t length
Definition: res_pktccops.c:106
unsigned char opcode
Definition: res_pktccops.c:104
#define malloc(a)
Definition: astmm.h:88
#define LOG_WARNING
Definition: logger.h:144
#define COPS_HEADER_SIZE
Definition: res_pktccops.c:69
char * msg
Definition: res_pktccops.c:108
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
char * contents
Definition: res_pktccops.c:98
unsigned char ctype
Definition: res_pktccops.c:97
#define free(a)
Definition: astmm.h:94
uint16_t length
Definition: res_pktccops.c:95
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
struct pktcobj * next
Definition: res_pktccops.c:99
struct pktcobj * object
Definition: res_pktccops.c:107
unsigned char verflag
Definition: res_pktccops.c:103
uint16_t clienttype
Definition: res_pktccops.c:105
#define SENDFLAGS
unsigned char cnum
Definition: res_pktccops.c:96
static void* do_pktccops ( void *  data)
static

Definition at line 702 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_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(), pktcobj::ctype, cops_gate::deltimer, free, 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, malloc, copsmsg::msg, cops_gate::mta, cops_cmts::name, cops_cmts::need_delete, pktcobj::next, 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, cops_gate::trid, and copsmsg::verflag.

Referenced by restart_pktc_thread().

703 {
704  int res, nfds, len;
705  struct copsmsg *recmsg, *sendmsg;
706  struct copsmsg recmsgb, sendmsgb;
707  struct pollfd *pfds = NULL, *tmp;
708  struct pktcobj *pobject;
709  struct cops_cmts *cmts;
710  struct cops_gate *gate;
711  char *sobjp;
712  uint16_t snst, sobjlen, scommand, recvtrid, actcount, reason, subreason;
713  uint32_t gateid, subscrid, pktcerror;
714  time_t last_exec = 0;
715 
716  recmsg = &recmsgb;
717  sendmsg = &sendmsgb;
718 
719  ast_debug(3, "COPS: thread started\n");
720 
721  for (;;) {
722  ast_free(pfds);
723  pfds = NULL;
724  nfds = 0;
726  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
727  if (last_exec != time(NULL)) {
728  if (cmts->state == 2 && cmts->katimer + cmts->keepalive < time(NULL)) {
729  ast_log(LOG_WARNING, "KA timer (%us) expired cmts: %s\n", cmts->keepalive, cmts->name);
730  cmts->state = 0;
731  cmts->katimer = -1;
732  close(cmts->sfd);
733  cmts->sfd = -1;
734  }
735  }
736  if (cmts->sfd > 0) {
737  if (!(tmp = ast_realloc(pfds, (nfds + 1) * sizeof(*pfds)))) {
738  continue;
739  }
740  pfds = tmp;
741  pfds[nfds].fd = cmts->sfd;
742  pfds[nfds].events = POLLIN;
743  pfds[nfds].revents = 0;
744  nfds++;
745  } else {
746  cmts->sfd = cops_connect(cmts->host, cmts->port);
747  if (cmts->sfd > 0) {
748  cmts->state = 1;
749  if (cmts->sfd > 0) {
750  if (!(tmp = ast_realloc(pfds, (nfds + 1) * sizeof(*pfds)))) {
751  continue;
752  }
753  pfds = tmp;
754  pfds[nfds].fd = cmts->sfd;
755  pfds[nfds].events = POLLIN;
756  pfds[nfds].revents = 0;
757  nfds++;
758  }
759  }
760  }
761  }
763 
764  if (last_exec != time(NULL)) {
765  last_exec = time(NULL);
768  if (gate) {
769  if (gate->deltimer && gate->deltimer < time(NULL)) {
770  gate->deltimer = time(NULL) + 5;
771  gate->trid = cops_trid++;
772  cops_gate_cmd(GATE_DEL, gate->cmts, gate->trid, 0, 0, 0, 0, 0, 0, gate);
773  ast_debug(3, "COPS: requested Gate-Del: CMTS: %s gateid: 0x%x\n", (gate->cmts) ? gate->cmts->name : "null", gate->gateid);
774  }
775  if (time(NULL) - gate->checked > gatetimeout) {
776  ast_debug(3, "COPS: remove from list GATE, CMTS: %s gateid: 0x%x\n", (gate->cmts) ? gate->cmts->name : "null", gate->gateid);
777  gate->state = GATE_TIMEOUT;
779  } else if (time(NULL) - gate->checked > gateinfoperiod && (gate->state == GATE_ALLOCATED || gate->state == GATE_OPEN)) {
780  if (gate->cmts && (!gate->in_transaction || ( gate->in_transaction + 5 ) < time(NULL))) {
781  gate->trid = cops_trid++;
782  ast_debug(3, "COPS: Gate-Info send to CMTS: %s gateid: 0x%x\n", gate->cmts->name, gate->gateid);
783  cops_gate_cmd(GATE_INFO, gate->cmts, gate->trid, gate->mta, 0, 0, 0, 0, 0, gate);
784  }
785  }
786  }
787  }
790  }
791 
792  if (pktcreload == 2) {
793  pktcreload = 0;
794  }
795  if ((res = ast_poll(pfds, nfds, 1000))) {
797  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
798  int idx;
799  if ((idx = ast_poll_fd_index(pfds, nfds, cmts->sfd)) > -1 && (pfds[idx].revents & POLLIN)) {
800  len = cops_getmsg(cmts->sfd, recmsg);
801  if (len > 0) {
802  ast_debug(3, "COPS: got from %s:\n Header: versflag=0x%.2x opcode=%i clienttype=0x%.4x msglength=%u\n",
803  cmts->name, (unsigned)recmsg->verflag,
804  recmsg->opcode, (unsigned)recmsg->clienttype, recmsg->length);
805  if (recmsg->object != NULL) {
806  pobject = recmsg->object;
807  while (pobject != NULL) {
808  ast_debug(3, " OBJECT: length=%i cnum=%i ctype=%i\n", pobject->length, pobject->cnum, pobject->ctype);
809  if (recmsg->opcode == 1 && pobject->cnum == 1 && pobject->ctype == 1 ) {
810  cmts->handle = ntohl(*((uint32_t *) pobject->contents));
811  ast_debug(3, " REQ client handle: %u\n", cmts->handle);
812  cmts->state = 2;
813  cmts->katimer = time(NULL);
814  } else if (pobject->cnum == 9 && pobject->ctype == 1) {
815  sobjp = pobject->contents;
816  subscrid = 0;
817  recvtrid = 0;
818  scommand = 0;
819  pktcerror = 0;
820  actcount = 0;
821  gateid = 0;
822  reason = 0;
823  subreason = 0;
824  while (sobjp < (pobject->contents + pobject->length - 4)) {
825  sobjlen = ntohs(*((uint16_t *) sobjp));
826  snst = ntohs(*((uint16_t *) (sobjp + 2)));
827  ast_debug(3, " S-Num S-type: 0x%.4x len: %i\n", (unsigned)snst, sobjlen);
828  if (snst == 0x0101 ) {
829  recvtrid = ntohs(*((uint16_t *) (sobjp + 4)));
830  scommand = ntohs(*((uint16_t *) (sobjp + 6)));
831  ast_debug(3, " Transaction Identifier command: %i trid %i\n", scommand, recvtrid);
832  } else if (snst == 0x0201) {
833  subscrid = ntohl(*((uint32_t *) (sobjp + 4)));
834  ast_debug(3, " Subscriber ID: 0x%.8x\n", subscrid);
835  } else if (snst == 0x0301) {
836  gateid = ntohl(*((uint32_t *) (sobjp + 4)));
837  ast_debug(3, " Gate ID: 0x%x 0x%.8x\n", gateid, gateid);
838  } else if (snst == 0x0401) {
839  actcount = ntohs(*((uint16_t *) (sobjp + 6)));
840  ast_debug(3, " Activity Count: %i\n", actcount);
841  } else if (snst == 0x0901) {
842  pktcerror = ntohl(*((uint32_t *) (sobjp + 4)));
843  ast_debug(3, " PKTC Error: 0x%.8x\n", pktcerror);
844  } else if (snst == 0x0d01) {
845  reason = ntohs(*((uint16_t *) (sobjp + 4)));
846  subreason = ntohs(*((uint16_t *) (sobjp + 6)));
847  ast_debug(3, " Reason: %d Subreason: %d\n", reason, subreason);
848  }
849  sobjp += sobjlen;
850  if (!sobjlen)
851  break;
852  }
853  if (scommand == PKTCCOPS_SCOMMAND_GATE_CLOSE || scommand == PKTCCOPS_SCOMMAND_GATE_OPEN) {
856  if (gate->cmts == cmts && gate->gateid == gateid) {
857  if (scommand == PKTCCOPS_SCOMMAND_GATE_CLOSE && gate->state != GATE_CLOSED && gate->state != GATE_CLOSED_ERR ) {
858  ast_debug(3, "COPS Gate Close Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
859  if (subreason) {
860  gate->state = GATE_CLOSED_ERR;
862  } else {
863  gate->state = GATE_CLOSED;
865  }
866  break;
867  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_OPEN && gate->state == GATE_ALLOCATED) {
868  ast_debug(3, "COPS Gate Open Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
869  gate->state = GATE_OPEN;
870  if (gate->gate_open) {
871  ast_debug(3, "Calling GATE-OPEN callback function\n");
872  gate->gate_open(gate);
873  gate->gate_open = NULL;
874  }
875  break;
876  }
877  }
878  }
884  if (gate->cmts == cmts && gate->trid == recvtrid) {
885  gate->gateid = gateid;
886  gate->checked = time(NULL);
887  if (scommand == PKTCCOPS_SCOMMAND_GATE_SET_ACK) {
888  ast_debug(3, "COPS Gate Set Ack Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
889  gate->state = GATE_ALLOCATED;
890  if (gate->got_dq_gi) {
891  gate->got_dq_gi(gate);
892  gate->got_dq_gi = NULL;
893  }
894  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_SET_ERR) {
895  ast_debug(3, "COPS Gate Set Error TrId: %i ErrorCode: 0x%.8x CMTS: %s\n ", recvtrid, pktcerror, cmts->name);
896  gate->state = GATE_ALLOC_FAILED;
897  if (gate->got_dq_gi) {
898  gate->got_dq_gi(gate);
899  gate->got_dq_gi = NULL;
900  }
902  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_INFO_ACK) {
903  ast_debug(3, "COPS Gate Info Ack Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
904  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_INFO_ERR) {
905  ast_debug(3, "COPS Gate Info Error Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
906  gate->state = GATE_ALLOC_FAILED;
908  } else if (scommand == PKTCCOPS_SCOMMAND_GATE_DELETE_ACK) {
909  ast_debug(3, "COPS Gate Deleted Gate ID: 0x%x TrId: %i CMTS: %s\n", gateid, recvtrid, cmts->name);
910  gate->state = GATE_DELETED;
912  }
913  gate->in_transaction = 0;
914  break;
915  }
916  }
919  }
920  }
921  pobject = pobject->next;
922  }
923  }
924 
925  if (recmsg->opcode == 6 && recmsg->object && recmsg->object->cnum == 11 && recmsg->object->ctype == 1) {
926  ast_debug(3, "COPS: Client open %s\n", cmts->name);
927  sendmsg->msg = NULL;
928  sendmsg->verflag = 0x10;
929  sendmsg->opcode = 7; /* Client Accept */
930  sendmsg->clienttype = 0x8008; /* =PacketCable */
932  sendmsg->object = malloc(sizeof(struct pktcobj));
933  sendmsg->object->length = 4 + COPS_OBJECT_HEADER_SIZE;
934  sendmsg->object->cnum = 10; /* keppalive timer*/
935  sendmsg->object->ctype = 1;
936  sendmsg->object->contents = malloc(sizeof(uint32_t));
937  *((uint32_t *) sendmsg->object->contents) = htonl(cmts->keepalive & 0x0000ffff);
938  sendmsg->object->next = NULL;
939  cops_sendmsg(cmts->sfd, sendmsg);
940  cops_freemsg(sendmsg);
941  } else if (recmsg->opcode == 9) {
942  ast_debug(3, "COPS: Keepalive Request got echoing back %s\n", cmts->name);
943  cops_sendmsg(cmts->sfd, recmsg);
944  cmts->state = 2;
945  cmts->katimer = time(NULL);
946  }
947  }
948  if (len <= 0) {
949  ast_debug(3, "COPS: lost connection to %s\n", cmts->name);
950  close(cmts->sfd);
951  cmts->sfd = -1;
952  cmts->state = 0;
953  }
954  cops_freemsg(recmsg);
955  }
956  }
958  }
959  if (pktcreload) {
960  ast_debug(3, "Reloading pktccops...\n");
964  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
965  cmts->need_delete = 1;
966  }
969  if (cmts && cmts->need_delete) {
970  AST_LIST_TRAVERSE(&gate_list, gate, list) {
971  if (gate->cmts == cmts) {
972  ast_debug(3, "Null gate %s\n", gate->cmts->name);
973  gate->cmts = NULL;
974  }
975  gate->in_transaction = 0;
976  }
978  ast_debug(3, "removing cmts: %s\n", cmts->name);
979  if (cmts->sfd > 0) {
980  close(cmts->sfd);
981  }
983  free(cmts);
984  }
985  }
989  pktcreload = 2;
990  }
991  pthread_testcancel();
992  }
993  return NULL;
994 }
uint32_t length
Definition: res_pktccops.c:106
#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:390
unsigned char opcode
Definition: res_pktccops.c:104
#define malloc(a)
Definition: astmm.h:88
int state
Definition: pktccops.h:59
time_t katimer
Definition: res_pktccops.c:147
static int gatetimeout
Definition: res_pktccops.c:166
#define PKTCCOPS_SCOMMAND_GATE_SET_ERR
Definition: res_pktccops.c:80
static int cops_connect(char *host, char *port)
Definition: res_pktccops.c:651
static int gateinfoperiod
Definition: res_pktccops.c:165
static void cops_freemsg(struct copsmsg *p)
Definition: res_pktccops.c:455
#define LOG_WARNING
Definition: logger.h:144
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define PKTCCOPS_DESTROY_CURRENT_GATE
Definition: res_pktccops.c:695
time_t deltimer
Definition: pktccops.h:62
char name[80]
Definition: res_pktccops.c:136
int(* gate_open)(struct cops_gate *gate)
Definition: pktccops.h:66
uint32_t handle
Definition: res_pktccops.c:144
#define PKTCCOPS_SCOMMAND_GATE_INFO_ACK
Definition: res_pktccops.c:82
#define COPS_HEADER_SIZE
Definition: res_pktccops.c:69
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
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:497
#define PKTCCOPS_SCOMMAND_GATE_INFO_ERR
Definition: res_pktccops.c:83
#define PKTCCOPS_SCOMMAND_GATE_DELETE_ACK
Definition: res_pktccops.c:85
#define PKTCCOPS_SCOMMAND_GATE_OPEN
Definition: res_pktccops.c:87
char * msg
Definition: res_pktccops.c:108
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
time_t checked
Definition: pktccops.h:61
#define ast_poll(a, b, c)
Definition: poll-compat.h:88
char * contents
Definition: res_pktccops.c:98
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
#define COPS_OBJECT_HEADER_SIZE
Definition: res_pktccops.c:70
uint16_t trid
Definition: pktccops.h:56
static int load_pktccops_config(void)
time_t in_transaction
Definition: pktccops.h:57
unsigned char ctype
Definition: res_pktccops.c:97
uint32_t gateid
Definition: pktccops.h:55
#define free(a)
Definition: astmm.h:94
int need_delete
Definition: res_pktccops.c:149
#define PKTCCOPS_SCOMMAND_GATE_SET_ACK
Definition: res_pktccops.c:79
uint16_t length
Definition: res_pktccops.c:95
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
static int pktcreload
Definition: res_pktccops.c:164
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static uint16_t cops_trid
Definition: res_pktccops.c:92
#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:97
#define PKTCCOPS_SCOMMAND_GATE_CLOSE
Definition: res_pktccops.c:88
struct pktcobj * next
Definition: res_pktccops.c:99
struct pktcobj * object
Definition: res_pktccops.c:107
uint32_t keepalive
Definition: res_pktccops.c:142
unsigned char verflag
Definition: res_pktccops.c:103
int(* got_dq_gi)(struct cops_gate *gate)
Definition: pktccops.h:64
#define ast_realloc(a, b)
Definition: astmm.h:103
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:325
char port[80]
Definition: res_pktccops.c:138
uint16_t clienttype
Definition: res_pktccops.c:105
uint32_t mta
Definition: pktccops.h:58
char host[80]
Definition: res_pktccops.c:137
unsigned char cnum
Definition: res_pktccops.c:96
struct cops_cmts * cmts
Definition: pktccops.h:63
static uint32_t ftoieeef ( float  n)
static

Definition at line 177 of file res_pktccops.c.

Referenced by cops_construct_gate().

178 {
179  uint32_t res;
180  memcpy(&res, &n, 4);
181  return htonl(res);
182 }
static int load_module ( void  )
static

Definition at line 1466 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().

1467 {
1468  int res;
1470  res = load_pktccops_config();
1472  if (res == -1) {
1473  return AST_MODULE_LOAD_DECLINE;
1474  }
1477  return 0;
1478 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
descriptor for a cli entry.
Definition: cli.h:165
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static struct ast_cli_entry cli_pktccops[]
static int load_pktccops_config(void)
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
static int restart_pktc_thread(void)
Definition: res_pktccops.c:996
static int load_pktccops_config ( void  )
static

Definition at line 1025 of file res_pktccops.c.

References 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(), cops_ippool::cmts, config, DEFAULT_COPS_PORT, f, gateinfoperiod, gatetimeout, cops_cmts::host, cops_cmts::keepalive, LOG_WARNING, ast_variable::name, cops_cmts::name, cops_cmts::need_delete, ast_variable::next, pktccops_add_ippool(), cops_cmts::port, cops_cmts::sfd, cops_ippool::start, cops_cmts::state, cops_ippool::stop, cops_cmts::t1, cops_cmts::t7, cops_cmts::t8, update(), and ast_variable::value.

Referenced by do_pktccops(), and load_module().

1026 {
1027  static char *cfg = "res_pktccops.conf";
1028  struct ast_config *config;
1029  struct ast_variable *v;
1030  struct cops_cmts *cmts;
1031  struct cops_ippool *new_ippool;
1032  const char *host, *cat, *port;
1033  int update;
1034  int res = 0;
1035  uint16_t t1_temp, t7_temp, t8_temp;
1036  uint32_t keepalive_temp;
1037  unsigned int a,b,c,d,e,f,g,h;
1038  struct ast_flags config_flags = {0};
1039 
1040  if (!(config = ast_config_load(cfg, config_flags))) {
1041  ast_log(LOG_WARNING, "Unable to load config file res_pktccops.conf\n");
1042  return -1;
1043  }
1044  for (cat = ast_category_browse(config, NULL); cat; cat = ast_category_browse(config, cat)) {
1045  if (!strcmp(cat, "general")) {
1046  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1047  if (!strcasecmp(v->name, "t1")) {
1048  t1 = atoi(v->value);
1049  } else if (!strcasecmp(v->name, "t7")) {
1050  t7 = atoi(v->value);
1051  } else if (!strcasecmp(v->name, "t8")) {
1052  t8 = atoi(v->value);
1053  } else if (!strcasecmp(v->name, "keepalive")) {
1054  keepalive = atoi(v->value);
1055  } else if (!strcasecmp(v->name, "gateinfoperiod")) {
1056  gateinfoperiod = atoi(v->value);
1057  } else if (!strcasecmp(v->name, "gatetimeout")) {
1058  gatetimeout = atoi(v->value);
1059  } else {
1060  ast_log(LOG_WARNING, "Unkown option %s in general section of res_ptkccops.conf\n", v->name);
1061  }
1062  }
1063  } else {
1064  /* Defaults */
1065  host = NULL;
1066  port = NULL;
1067  t1_temp = t1;
1068  t7_temp = t7;
1069  t8_temp = t8;
1070  keepalive_temp = keepalive;
1071 
1072  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1073  if (!strcasecmp(v->name, "host")) {
1074  host = v->value;
1075  } else if (!strcasecmp(v->name, "port")) {
1076  port = v->value;
1077  } else if (!strcasecmp(v->name, "t1")) {
1078  t1_temp = atoi(v->value);
1079  } else if (!strcasecmp(v->name, "t7")) {
1080  t7_temp = atoi(v->value);
1081  } else if (!strcasecmp(v->name, "t8")) {
1082  t8_temp = atoi(v->value);
1083  } else if (!strcasecmp(v->name, "keepalive")) {
1084  keepalive_temp = atoi(v->value);
1085  } else if (!strcasecmp(v->name, "pool")) {
1086  /* we weill parse it in 2nd round */
1087  } else {
1088  ast_log(LOG_WARNING, "Unkown option %s in res_ptkccops.conf\n", v->name);
1089  }
1090  }
1091 
1092  update = 0;
1093  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1094  if (!strcmp(cmts->name, cat)) {
1095  update = 1;
1096  break;
1097  }
1098 
1099  }
1100  if (!update) {
1101  cmts = ast_calloc(1, sizeof(*cmts));
1102  if (!cmts) {
1103  res = -1;
1104  break;
1105  }
1106  AST_LIST_INSERT_HEAD(&cmts_list, cmts, list);
1107  }
1108  if (cat) {
1109  ast_copy_string(cmts->name, cat, sizeof(cmts->name));
1110  }
1111  if (host) {
1112  ast_copy_string(cmts->host, host, sizeof(cmts->host));
1113  }
1114  if (port) {
1115  ast_copy_string(cmts->port, port, sizeof(cmts->port));
1116  } else {
1117  ast_copy_string(cmts->port, DEFAULT_COPS_PORT, sizeof(cmts->port));
1118  }
1119 
1120  cmts->t1 = t1_temp;
1121  cmts->t7 = t7_temp;
1122  cmts->t8 = t8_temp;
1123  cmts->keepalive = keepalive_temp;
1124  if (!update) {
1125  cmts->state = 0;
1126  cmts->sfd = -1;
1127  }
1128  cmts->need_delete = 0;
1129  for (v = ast_variable_browse(config, cat); v; v = v->next) {
1130  /* parse ipppol when we have cmts ptr */
1131  if (!strcasecmp(v->name, "pool")) {
1132  if (sscanf(v->value, "%3u.%3u.%3u.%3u %3u.%3u.%3u.%3u", &a, &b, &c, &d, &e, &f, &g, &h) == 8) {
1133  new_ippool = ast_calloc(1, sizeof(*new_ippool));
1134  if (!new_ippool) {
1135  res = -1;
1136  break;
1137  }
1138  new_ippool->start = a << 24 | b << 16 | c << 8 | d;
1139  new_ippool->stop = e << 24 | f << 16 | g << 8 | h;
1140  new_ippool->cmts = cmts;
1141  pktccops_add_ippool(new_ippool);
1142  } else {
1143  ast_log(LOG_WARNING, "Invalid ip pool format in res_pktccops.conf\n");
1144  }
1145  }
1146  }
1147  }
1148  }
1149  ast_config_destroy(config);
1150  return res;
1151 }
static const char config[]
Definition: cdr_csv.c:57
static int pktccops_add_ippool(struct cops_ippool *ippool)
static uint32_t keepalive
Definition: res_pktccops.c:162
static int gatetimeout
Definition: res_pktccops.c:166
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:165
#define LOG_WARNING
Definition: logger.h:144
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
char name[80]
Definition: res_pktccops.c:136
static uint16_t t7
Definition: res_pktccops.c:160
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
uint32_t start
Definition: res_pktccops.c:154
const char * value
Definition: config.h:79
#define ast_config_load(filename, flags)
Load a config file.
Definition: config.h:170
uint16_t t7
Definition: res_pktccops.c:140
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
const char * name
Definition: config.h:77
static uint16_t t8
Definition: res_pktccops.c:161
int need_delete
Definition: res_pktccops.c:149
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
uint16_t t1
Definition: res_pktccops.c:139
#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:696
struct cops_cmts * cmts
Definition: res_pktccops.c:156
static struct ast_format f[]
Definition: format_g726.c:181
Structure used to handle boolean flags.
Definition: utils.h:200
uint32_t keepalive
Definition: res_pktccops.c:142
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
uint32_t stop
Definition: res_pktccops.c:155
struct ast_variable * next
Definition: config.h:82
uint16_t t8
Definition: res_pktccops.c:141
#define DEFAULT_COPS_PORT
Definition: res_pktccops.c:67
char port[80]
Definition: res_pktccops.c:138
char host[80]
Definition: res_pktccops.c:137
static uint16_t t1
Definition: res_pktccops.c:159
static int pktccops_add_ippool ( struct cops_ippool ippool)
static

Definition at line 1423 of file res_pktccops.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), and LOG_WARNING.

Referenced by load_pktccops_config().

1424 {
1425  if (ippool) {
1427  AST_LIST_INSERT_HEAD(&ippool_list, ippool, list);
1429  return 0;
1430  } else {
1431  ast_log(LOG_WARNING, "Attempted to register NULL ippool?\n");
1432  return -1;
1433  }
1434 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define LOG_WARNING
Definition: logger.h:144
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:696
static char* pktccops_debug ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1386 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, pktccopsdebug, and ast_cli_entry::usage.

1387 {
1388  switch (cmd) {
1389  case CLI_INIT:
1390  e->command = "pktccops set debug {on|off}";
1391  e->usage =
1392  "Usage: pktccops set debug {on|off}\n"
1393  " Turn on/off debuging\n";
1394  return NULL;
1395  case CLI_GENERATE:
1396  return NULL;
1397  }
1398 
1399  if (a->argc != e->args)
1400  return CLI_SHOWUSAGE;
1401  if (!strncasecmp(a->argv[e->args - 1], "on", 2)) {
1402  pktccopsdebug = 1;
1403  ast_cli(a->fd, "PktcCOPS Debugging Enabled\n");
1404  } else if (!strncasecmp(a->argv[e->args - 1], "off", 2)) {
1405  pktccopsdebug = 0;
1406  ast_cli(a->fd, "PktcCOPS Debugging Disabled\n");
1407  } else {
1408  return CLI_SHOWUSAGE;
1409  }
1410  return CLI_SUCCESS;
1411 
1412 }
const int argc
Definition: cli.h:154
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static int pktccopsdebug
Definition: res_pktccops.c:163
static char* pktccops_gatedel ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1269 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(), ast_cli_args::fd, GATE_DEL, cops_gate::gateid, cops_cmts::name, and ast_cli_entry::usage.

1270 {
1271  int found = 0;
1272  int trid;
1273  uint32_t gateid;
1274  struct cops_gate *gate;
1275  struct cops_cmts *cmts;
1276 
1277  switch (cmd) {
1278  case CLI_INIT:
1279  e->command = "pktccops gatedel";
1280  e->usage =
1281  "Usage: pktccops gatedel <cmts> <gateid>\n"
1282  " Send Gate-Del to cmts.\n";
1283  return NULL;
1284  case CLI_GENERATE:
1285  return NULL;
1286  }
1287 
1288  if (a->argc < 4)
1289  return CLI_SHOWUSAGE;
1290 
1292  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1293  if (!strcmp(cmts->name, a->argv[2])) {
1294  ast_cli(a->fd, "Found cmts: %s\n", cmts->name);
1295  found = 1;
1296  break;
1297  }
1298  }
1300 
1301  if (!found)
1302  return CLI_SHOWUSAGE;
1303 
1304  trid = cops_trid++;
1305  if (!sscanf(a->argv[3], "%x", &gateid)) {
1306  ast_cli(a->fd, "bad gate specification (%s)\n", a->argv[3]);
1307  return CLI_SHOWUSAGE;
1308  }
1309 
1310  found = 0;
1312  AST_LIST_TRAVERSE(&gate_list, gate, list) {
1313  if (gate->gateid == gateid && gate->cmts == cmts) {
1314  found = 1;
1315  break;
1316  }
1317  }
1318 
1319  if (!found) {
1320  ast_cli(a->fd, "gate not found: %s\n", a->argv[3]);
1321  return CLI_SHOWUSAGE;
1322  }
1323 
1325  cops_gate_cmd(GATE_DEL, cmts, trid, 0, 0, 0, 0, 0, 0, gate);
1326  return CLI_SUCCESS;
1327 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
const int argc
Definition: cli.h:154
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:146
char name[80]
Definition: res_pktccops.c:136
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
struct cops_cmts::@344 list
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:497
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
uint32_t gateid
Definition: pktccops.h:55
#define CLI_SHOWUSAGE
Definition: cli.h:44
static uint16_t cops_trid
Definition: res_pktccops.c:92
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
struct cops_cmts * cmts
Definition: pktccops.h:63
static char* pktccops_gateset ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1329 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(), ast_cli_args::fd, GATE_SET, cops_cmts::name, and ast_cli_entry::usage.

1330 {
1331  int foundcmts = 0;
1332  int trid;
1333  unsigned int an,bn,cn,dn;
1334  uint32_t mta, ssip;
1335  struct cops_cmts *cmts;
1336 
1337  switch (cmd) {
1338  case CLI_INIT:
1339  e->command = "pktccops gateset";
1340  e->usage =
1341  "Usage: pktccops gateset <cmts> <mta> <acctcount> <bitrate> <packet size> <switch ip> <switch port>\n"
1342  " Send Gate-Set to cmts.\n";
1343  return NULL;
1344  case CLI_GENERATE:
1345  return NULL;
1346  }
1347 
1348  if (a->argc < 9)
1349  return CLI_SHOWUSAGE;
1350 
1351  if (!strcmp(a->argv[2], "null")) {
1352  cmts = NULL;
1353  } else {
1355  AST_LIST_TRAVERSE(&cmts_list, cmts, list) {
1356  if (!strcmp(cmts->name, a->argv[2])) {
1357  ast_cli(a->fd, "Found cmts: %s\n", cmts->name);
1358  foundcmts = 1;
1359  break;
1360  }
1361  }
1363  if (!foundcmts) {
1364  ast_cli(a->fd, "CMTS not found: %s\n", a->argv[2]);
1365  return CLI_SHOWUSAGE;
1366  }
1367  }
1368 
1369  trid = cops_trid++;
1370  if (sscanf(a->argv[3], "%3u.%3u.%3u.%3u", &an, &bn, &cn, &dn) != 4) {
1371  ast_cli(a->fd, "MTA specification (%s) does not look like an ipaddr\n", a->argv[3]);
1372  return CLI_SHOWUSAGE;
1373  }
1374  mta = an << 24 | bn << 16 | cn << 8 | dn;
1375 
1376  if (sscanf(a->argv[7], "%3u.%3u.%3u.%3u", &an, &bn, &cn, &dn) != 4) {
1377  ast_cli(a->fd, "SSIP specification (%s) does not look like an ipaddr\n", a->argv[7]);
1378  return CLI_SHOWUSAGE;
1379  }
1380  ssip = an << 24 | bn << 16 | cn << 8 | dn;
1381 
1382  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);
1383  return CLI_SUCCESS;
1384 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
const int argc
Definition: cli.h:154
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:146
char name[80]
Definition: res_pktccops.c:136
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
struct cops_cmts::@344 list
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:497
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
static uint16_t cops_trid
Definition: res_pktccops.c:92
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static char* pktccops_show_cmtses ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1153 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::name, cops_cmts::port, cops_cmts::state, and ast_cli_entry::usage.

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

Definition at line 1190 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, cops_gate::state, and ast_cli_entry::usage.

1191 {
1192  struct cops_gate *gate;
1193  char state_desc[16];
1194 
1195  switch(cmd) {
1196  case CLI_INIT:
1197  e->command = "pktccops show gates";
1198  e->usage =
1199  "Usage: pktccops show gates\n"
1200  " List PacketCable COPS GATEs.\n";
1201 
1202  return NULL;
1203  case CLI_GENERATE:
1204  return NULL;
1205  }
1206 
1207  ast_cli(a->fd, "%-16s %-12s %-12s %-10s %-10s %-10s\n" ,"CMTS", "Gate-Id","MTA", "Status", "AllocTime", "CheckTime");
1208  ast_cli(a->fd, "%-16s %-12s %-12s %-10s %-10s %-10s\n" ,"--------------" ,"----------", "----------", "--------", "--------", "--------\n");
1211  AST_LIST_TRAVERSE(&gate_list, gate, list) {
1212  if (gate->state == GATE_ALLOC_FAILED) {
1213  ast_copy_string(state_desc, "Failed", sizeof(state_desc));
1214  } else if (gate->state == GATE_ALLOC_PROGRESS) {
1215  ast_copy_string(state_desc, "In Progress", sizeof(state_desc));
1216  } else if (gate->state == GATE_ALLOCATED) {
1217  ast_copy_string(state_desc, "Allocated", sizeof(state_desc));
1218  } else if (gate->state == GATE_CLOSED) {
1219  ast_copy_string(state_desc, "Closed", sizeof(state_desc));
1220  } else if (gate->state == GATE_CLOSED_ERR) {
1221  ast_copy_string(state_desc, "ClosedErr", sizeof(state_desc));
1222  } else if (gate->state == GATE_OPEN) {
1223  ast_copy_string(state_desc, "Open", sizeof(state_desc));
1224  } else if (gate->state == GATE_DELETED) {
1225  ast_copy_string(state_desc, "Deleted", sizeof(state_desc));
1226  } else {
1227  ast_copy_string(state_desc, "N/A", sizeof(state_desc));
1228  }
1229 
1230  ast_cli(a->fd, "%-16s 0x%.8x 0x%08x %-10s %10i %10i %u\n", (gate->cmts) ? gate->cmts->name : "null" , gate->gateid, gate->mta,
1231  state_desc, (int) (time(NULL) - gate->allocated), (gate->checked) ? (int) (time(NULL) - gate->checked) : 0, (unsigned int) gate->in_transaction);
1232  }
1235  return CLI_SUCCESS;
1236 }
#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:146
char name[80]
Definition: res_pktccops.c:136
time_t allocated
Definition: pktccops.h:60
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
const int fd
Definition: cli.h:153
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:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
uint32_t mta
Definition: pktccops.h:58
struct cops_cmts * cmts
Definition: pktccops.h:63
static char* pktccops_show_pools ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1238 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_cmts::name, cops_ippool::start, cops_ippool::stop, stop, and ast_cli_entry::usage.

1239 {
1240  struct cops_ippool *ippool;
1241  char start[32];
1242  char stop[32];
1243 
1244  switch(cmd) {
1245  case CLI_INIT:
1246  e->command = "pktccops show pools";
1247  e->usage =
1248  "Usage: pktccops show pools\n"
1249  " List PacketCable COPS ip pools of MTAs.\n";
1250 
1251  return NULL;
1252  case CLI_GENERATE:
1253  return NULL;
1254  }
1255 
1256  ast_cli(a->fd, "%-16s %-18s %-7s\n", "Start ", "Stop ", "CMTS ");
1257  ast_cli(a->fd, "%-16s %-18s %-7s\n", "----------", "----------", "--------");
1259  AST_LIST_TRAVERSE(&ippool_list, ippool, list) {
1260  snprintf(start, sizeof(start), "%3u.%3u.%3u.%3u", ippool->start >> 24, (ippool->start >> 16) & 0x000000ff, (ippool->start >> 8) & 0x000000ff, ippool->start & 0x000000ff);
1261 
1262  snprintf(stop, sizeof(stop), "%3u.%3u.%3u.%3u", ippool->stop >> 24, (ippool->stop >> 16) & 0x000000ff, (ippool->stop >> 8) & 0x000000ff, ippool->stop & 0x000000ff);
1263  ast_cli(a->fd, "%-16s %-18s %-16s\n", start, stop, ippool->cmts->name);
1264  }
1266  return CLI_SUCCESS;
1267 }
#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
Definition: cli.h:146
unsigned int stop
Definition: app_meetme.c:969
char name[80]
Definition: res_pktccops.c:136
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
uint32_t start
Definition: res_pktccops.c:154
const int fd
Definition: cli.h:153
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct cops_ippool::@345 list
char * command
Definition: cli.h:180
struct cops_cmts * cmts
Definition: res_pktccops.c:156
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
uint32_t stop
Definition: res_pktccops.c:155
static void pktccops_unregister_cmtses ( void  )
static

Definition at line 1436 of file res_pktccops.c.

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

Referenced by unload_module().

1437 {
1438  struct cops_cmts *cmts;
1439  struct cops_gate *gate;
1441  while ((cmts = AST_LIST_REMOVE_HEAD(&cmts_list, list))) {
1442  if (cmts->sfd > 0) {
1443  close(cmts->sfd);
1444  }
1445  free(cmts);
1446  }
1448 
1450  while ((gate = AST_LIST_REMOVE_HEAD(&gate_list, list))) {
1451  free(gate);
1452  }
1454 }
#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:818
#define free(a)
Definition: astmm.h:94
static void pktccops_unregister_ippools ( void  )
static

Definition at line 1456 of file res_pktccops.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, and free.

Referenced by do_pktccops(), and unload_module().

1457 {
1458  struct cops_ippool *ippool;
1460  while ((ippool = AST_LIST_REMOVE_HEAD(&ippool_list, list))) {
1461  free(ippool);
1462  }
1464 }
#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:818
#define free(a)
Definition: astmm.h:94
struct cops_ippool::@345 list
static int reload_module ( void  )
static

Definition at line 1502 of file res_pktccops.c.

References ast_log(), LOG_NOTICE, and pktcreload.

1503 {
1504  /* Prohibit unloading */
1505  if (pktcreload) {
1506  ast_log(LOG_NOTICE, "Previous reload in progress, please wait!\n");
1507  return -1;
1508  }
1509  pktcreload = 1;
1510  return 0;
1511 }
static int pktcreload
Definition: res_pktccops.c:164
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
static int restart_pktc_thread ( void  )
static

Definition at line 996 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, and pktccops_lock.

Referenced by load_module().

997 {
999  return 0;
1000  }
1001  if (ast_mutex_lock(&pktccops_lock)) {
1002  ast_log(LOG_WARNING, "Unable to lock pktccops\n");
1003  return -1;
1004  }
1005  if (pktccops_thread == pthread_self()) {
1007  ast_log(LOG_WARNING, "Cannot kill myself\n");
1008  return -1;
1009  }
1011  /* Wake up the thread */
1012  pthread_kill(pktccops_thread, SIGURG);
1013  } else {
1014  /* Start a new monitor */
1017  ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
1018  return -1;
1019  }
1020  }
1022  return 0;
1023 }
static ast_mutex_t pktccops_lock
Definition: res_pktccops.c:90
static pthread_t pktccops_thread
Definition: res_pktccops.c:91
#define LOG_WARNING
Definition: logger.h:144
#define ast_mutex_lock(a)
Definition: lock.h:155
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:426
#define AST_PTHREADT_NULL
Definition: lock.h:65
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void * do_pktccops(void *data)
Definition: res_pktccops.c:702
#define AST_PTHREADT_STOP
Definition: lock.h:66
#define ast_mutex_unlock(a)
Definition: lock.h:156
static int unload_module ( void  )
static

Definition at line 1480 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, pktccops_lock, pktccops_unregister_cmtses(), and pktccops_unregister_ippools().

1481 {
1482  if (!ast_mutex_lock(&pktccops_lock)) {
1484  pthread_cancel(pktccops_thread);
1485  pthread_kill(pktccops_thread, SIGURG);
1486  pthread_join(pktccops_thread, NULL);
1487  }
1490  } else {
1491  ast_log(LOG_ERROR, "Unable to lock the pktccops_thread\n");
1492  return -1;
1493  }
1494 
1499  return 0;
1500 }
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
static ast_mutex_t pktccops_lock
Definition: res_pktccops.c:90
static pthread_t pktccops_thread
Definition: res_pktccops.c:91
descriptor for a cli entry.
Definition: cli.h:165
static struct ast_cli_entry cli_pktccops[]
#define ast_mutex_lock(a)
Definition: lock.h:155
#define AST_PTHREADT_NULL
Definition: lock.h:65
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_PTHREADT_STOP
Definition: lock.h:66
static void pktccops_unregister_cmtses(void)
static void pktccops_unregister_ippools(void)
#define ast_mutex_unlock(a)
Definition: lock.h:156

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload_module, }
static

Definition at line 1517 of file res_pktccops.c.

Definition at line 1517 of file res_pktccops.c.

struct ast_cli_entry cli_pktccops[]
static

Definition at line 1414 of file res_pktccops.c.

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

Definition at line 92 of file res_pktccops.c.

struct gate_list gate_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } , }
int gateinfoperiod = 60
static

Definition at line 165 of file res_pktccops.c.

Referenced by do_pktccops(), and load_pktccops_config().

int gatetimeout = 150
static

Definition at line 166 of file res_pktccops.c.

Referenced by do_pktccops(), and load_pktccops_config().

struct ippool_list ippool_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } , }
uint32_t keepalive = 60
static

Definition at line 162 of file res_pktccops.c.

ast_mutex_t pktccops_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
static

Definition at line 90 of file res_pktccops.c.

Referenced by restart_pktc_thread(), and unload_module().

pthread_t pktccops_thread = AST_PTHREADT_NULL
static

Definition at line 91 of file res_pktccops.c.

int pktccopsdebug = 0
static

Definition at line 163 of file res_pktccops.c.

Referenced by cops_gate_cmd(), and pktccops_debug().

int pktcreload = 0
static

Definition at line 164 of file res_pktccops.c.

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

uint16_t t1 = 250
static

Definition at line 159 of file res_pktccops.c.

Referenced by create_match_char_tree(), dahdi_bridge(), differ_by_repeat(), and is_prefix().

uint16_t t7 = 200
static

Definition at line 160 of file res_pktccops.c.

uint16_t t8 = 300
static

Definition at line 161 of file res_pktccops.c.