Changeset fe86d3c9f8a229a788a863d1855c9e3d616b04ea

Show
Ignore:
Timestamp:
02/26/10 13:37:05 (5 months ago)
Author:
Holger Hans Peter Freyther <zecke@selfish.org>
Parents:
a820c5f89d0ea3a7aefd1621d9bf1c9c5a25e8eb
Children:
ef6bb25aa5b7dcb4a10469c6a39ace3534c08376
git-committer:
Holger Hans Peter Freyther <zecke@selfish.org> / 2010-02-26T13:37:05Z+0100
Message:

[mgcp] Introduce a policy CB for the MGCP protocol

The are three policies. Accept, Reject and Defer. This will
allow to handle network connections and such from the policy
callback instead of directly acting on it.

Location:
openbsc
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • openbsc/include/openbsc/mgcp.h

    r154b955 rfe86d3c  
    6666#define MGCP_ENDP_MDCX 3 
    6767 
     68/* 
     69 * what to do with the msg? 
     70 *      - continue as usual? 
     71 *      - reject and send a failure code? 
     72 *      - defer? do not send anything 
     73 */ 
     74#define MGCP_POLICY_CONT        4 
     75#define MGCP_POLICY_REJECT      5 
     76#define MGCP_POLICY_DEFER       6 
     77 
    6878typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state, int local_rtp); 
     79typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id); 
    6980 
    7081struct mgcp_config { 
     
    8697 
    8798        mgcp_change change_cb; 
     99        mgcp_policy policy_cb; 
     100        void *data; 
    88101 
    89102        struct mgcp_endpoint *endpoints; 
  • openbsc/src/mgcp/mgcp_protocol.c

    ra820c5f rfe86d3c  
    456456                goto error2; 
    457457 
     458        /* policy CB */ 
     459        if (cfg->policy_cb) { 
     460                switch (cfg->policy_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_CRCX, trans_id)) { 
     461                case MGCP_POLICY_REJECT: 
     462                        LOGP(DMGCP, LOGL_NOTICE, "CRCX rejected by policy on 0x%x\n", 
     463                             ENDPOINT_NUMBER(endp)); 
     464                        mgcp_free_endp(endp); 
     465                        return create_response(500, "CRCX", trans_id); 
     466                        break; 
     467                case MGCP_POLICY_DEFER: 
     468                        /* stop processing */ 
     469                        return NULL; 
     470                        break; 
     471                case MGCP_POLICY_CONT: 
     472                        /* just continue */ 
     473                        break; 
     474                } 
     475        } 
     476 
    458477        LOGP(DMGCP, LOGL_NOTICE, "Creating endpoint on: 0x%x CI: %u port: %u\n", 
    459478                ENDPOINT_NUMBER(endp), endp->ci, endp->rtp_port); 
     
    549568        MSG_TOKENIZE_END 
    550569 
     570        /* policy CB */ 
     571        if (cfg->policy_cb) { 
     572                switch (cfg->policy_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_MDCX, trans_id)) { 
     573                case MGCP_POLICY_REJECT: 
     574                        LOGP(DMGCP, LOGL_NOTICE, "MDCX rejected by policy on 0x%x\n", 
     575                             ENDPOINT_NUMBER(endp)); 
     576                        return create_response(500, "MDCX", trans_id); 
     577                        break; 
     578                case MGCP_POLICY_DEFER: 
     579                        /* stop processing */ 
     580                        return NULL; 
     581                        break; 
     582                case MGCP_POLICY_CONT: 
     583                        /* just continue */ 
     584                        break; 
     585                } 
     586        } 
     587 
    551588        /* modify */ 
    552589        LOGP(DMGCP, LOGL_NOTICE, "Modified endpoint on: 0x%x Server: %s:%u\n", 
     
    603640        MSG_TOKENIZE_END 
    604641 
     642        /* policy CB */ 
     643        if (cfg->policy_cb) { 
     644                switch (cfg->policy_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_DLCX, trans_id)) { 
     645                case MGCP_POLICY_REJECT: 
     646                        LOGP(DMGCP, LOGL_NOTICE, "DLCX rejected by policy on 0x%x\n", 
     647                             ENDPOINT_NUMBER(endp)); 
     648                        return create_response(500, "DLCX", trans_id); 
     649                        break; 
     650                case MGCP_POLICY_DEFER: 
     651                        /* stop processing */ 
     652                        return NULL; 
     653                        break; 
     654                case MGCP_POLICY_CONT: 
     655                        /* just continue */ 
     656                        break; 
     657                } 
     658        } 
     659 
    605660        /* free the connection */ 
    606661        mgcp_free_endp(endp);