psd_server.c File Reference

Interface and implementation for the policy server. More...

#include <sync/common.h>
#include <sync/psd_ipc.h>
#include <fnmatch.h>
#include "psd_config.h"
#include "psd_server.h"
#include "psd_logging.h"

Go to the source code of this file.

Data Structures

struct  psd_ipc_conn_s

Defines

#define MAX_IPC_CONN   64
 maximum number of connections
#define MAX_IPC_WAIT_CONN   3
 maximum number of connections waiting
#define BUFFER_SIZE   1024
 Send buffer size in bytes for any pipes / sockets.
#define evInitID(id)   ((id)->opaque = NULL)
 initialize the evFileID
#define evTestID(id)   ((id).opaque != NULL)
 Test if the evFileID has been initialized.

Typedefs

typedef psd_ipc_conn_s psd_ipc_conn_t

Functions

static void connect_table_init (void)
static boolean connect_table_add (psd_ipc_conn_t *conn)
static boolean connect_table_del (psd_ipc_conn_t *conn)
static void psd_ipc_shutdown_conn (psd_ipc_conn_t *conn)
static psd_policy_tlookup_policy (policy_req_msg_t *req)
static void send_msg (ipc_pipe_t *ipc_pipe, msg_type_e msg_type, void *data, int len)
static void psd_ipc_dispatch (evContext ctx __unused, void *uap, int sockfd __unused, int eventmask)
static void psd_ipc_connect (evContext ctx __unused, void *uap __unused, int sockfd, const void *la, int lalen, const void *ra, int ralen)
int server_init (evContext ctx)
void notify_all_clients (void)
int server_shutdown (void)

Variables

static psd_ipc_conn_tconnect_table [MAX_IPC_CONN]
 client connections
static evConnID server_conn_id
static evContext psd_ctx


Detailed Description

Interface and implementation for the policy server.

Functions to initialize the server functionality and lookup a policy

Definition in file psd_server.c.


Typedef Documentation

typedef struct psd_ipc_conn_s psd_ipc_conn_t

Connection information bundle


Function Documentation

static boolean connect_table_add ( psd_ipc_conn_t conn  )  [static]

Add connection to the table.

Parameters:
[in] conn Pointer to connection data.
Returns:
TRUE if successful, otherwise FALSE if table is full.

Definition at line 111 of file psd_server.c.

References connect_table, and MAX_IPC_CONN.

Referenced by psd_ipc_connect().

static boolean connect_table_del ( psd_ipc_conn_t conn  )  [static]

Remove connection from the table. Caller should free connection.

Parameters:
[in] conn Pointer to connection data.
Returns:
TRUE if successful, otherwise FALSE if didn't find the connection.

Definition at line 136 of file psd_server.c.

References connect_table, and MAX_IPC_CONN.

Referenced by psd_ipc_shutdown_conn().

static void connect_table_init ( void   )  [static]

Initialize connect table.

Definition at line 91 of file psd_server.c.

References connect_table, and MAX_IPC_CONN.

Referenced by server_init().

static psd_policy_t* lookup_policy ( policy_req_msg_t req  )  [static]

Find the first known policy that matches from the set of configured expressions given interface name and address family.

Parameters:
[in] req Policy request message from client.
Returns:
The policy matching request, otherwise NULL.

Definition at line 193 of file psd_server.c.

References policy_req_msg_s::af, psd_policy_s::af, first_policy(), policy_req_msg_s::ifname, psd_policy_s::ifname, and next_policy().

Referenced by psd_ipc_dispatch().

void notify_all_clients ( void   ) 

Notify all currently connected clients to update policies.

Definition at line 590 of file psd_server.c.

References connect_table, MAX_IPC_CONN, MSG_POLICY_UPDATE, and send_msg().

Referenced by psd_config_read().

static void psd_ipc_connect ( evContext ctx  __unused,
void *uap  __unused,
int  sockfd,
const void *  la,
int  lalen,
const void *  ra,
int  ralen 
) [static]

A callback for evListen registered in server_init, this function accepts an incoming connection, builds the connection structure that holds the pipe, socket and evFileID, and lastly registers the callback function psd_ipc_dispatch for subsequent reads (of requests).

Parameters:
[in] ctx The eventlib context
[in] uap The user data registered to be passed to this callback function
[in] sockfd The socket's file descriptor
[in] la The local address (needs typecasting to) (const struct sockaddr_in *)
[in] lalen The local address structure's length in bytes
[in] ra The remote address (needs typecasting to) (const struct sockaddr_in *)
[in] ralen The remote address structure's length in bytes

Definition at line 450 of file psd_server.c.

References BUFFER_SIZE, connect_table_add(), evInitID, psd_ctx, psd_ipc_dispatch(), and psd_ipc_shutdown_conn().

Referenced by server_init().

static void psd_ipc_dispatch ( evContext ctx  __unused,
void *  uap,
int sockfd  __unused,
int  eventmask 
) [static]

A callback for evSelectFD registered in psd_ipc_connect, this function accepts an incoming message (it reads) from the existing connection.

Parameters:
[in] ctx The eventlib context
[in] uap The user data registered to be passed to this callback function. In our case this is the connection structure built in psd_ipc_connect that contains the IPC pipe.
[in] sockfd The socket's file descriptor
[in] eventmask A bit mask of events that generated the select to unblock and call this function. In our case we only registered to listen to reads and exceptions so we know this is a read or exception.

Definition at line 271 of file psd_server.c.

References psd_policy_s::filter, psd_policy_filter_s::filter_data, IPC_MSG_TYPE_PSD, lookup_policy(), MSG_FILTER, MSG_HB, MSG_POLICY_NA, MSG_POLICY_REQ, MSG_ROUTE, MSG_UPDATE_DONE, psd_policy_route_s::next, psd_ipc_conn_s::pipe, psd_ipc_shutdown_conn(), psd_policy_s::route, psd_policy_route_s::route_data, and send_msg().

Referenced by psd_ipc_connect().

static void psd_ipc_shutdown_conn ( psd_ipc_conn_t conn  )  [static]

Shutdown / close pipe associated with this connection struct (socket)

Parameters:
[in] conn The connection to close

Definition at line 157 of file psd_server.c.

References connect_table_del(), evInitID, evTestID, psd_ipc_conn_s::id, psd_ipc_conn_s::pipe, psd_ctx, and psd_ipc_conn_s::socket.

Referenced by psd_ipc_connect(), psd_ipc_dispatch(), and server_shutdown().

static void send_msg ( ipc_pipe_t *  ipc_pipe,
msg_type_e  msg_type,
void *  data,
int  len 
) [static]

Send message to client.

Parameters:
[in] ipc_pipe Pointer to the pipe.
[in] msg_type Message type.
[in] data Pointer to the message data.
[in] len Message length.

Definition at line 227 of file psd_server.c.

References IPC_MSG_TYPE_PSD.

Referenced by notify_all_clients(), and psd_ipc_dispatch().

int server_init ( evContext  ctx  ) 

Initialize the server socket and start listening for new connections. It binds to inet0 and listens on port PSD_PORT_NUM. It also calls evListen which registers psd_ipc_connect as the callback function to accept new incoming connections.

Parameters:
[in] ctx Eventlib context for this application.
Returns:
SUCCESS if successful, or EFAIL if failed.

Definition at line 511 of file psd_server.c.

References BUFFER_SIZE, connect_table_init(), evInitID, MAX_IPC_WAIT_CONN, psd_ctx, psd_ipc_connect(), PSD_PORT_NUM, and server_conn_id.

Referenced by psd_init().

int server_shutdown ( void   ) 

Shutdown the server socket that accecpts new connections (only used when stopping/restarting the daemon)

Returns:
SUCCESS if the server connection id wasn't set because the initial call to listen failed, or if it was, then if we successfully stop listening for connections; or EFAIL if we were listening, but the attempt to stop listening for connections failed.

Definition at line 615 of file psd_server.c.

References connect_table, evInitID, evTestID, MAX_IPC_CONN, psd_ctx, psd_ipc_shutdown_conn(), and server_conn_id.


Variable Documentation

evContext psd_ctx [static]

Event context for psd

Definition at line 81 of file psd_server.c.

Referenced by psd_ipc_connect(), psd_ipc_shutdown_conn(), server_init(), and server_shutdown().

evConnID server_conn_id [static]

Connection ID for the server socket accepting new connections

Definition at line 76 of file psd_server.c.

Referenced by server_init(), and server_shutdown().


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:27:07 2010 for SDK Your Net Corporation Policy Manager Example: Policy Server Daemon 1.0 by Doxygen 1.5.1