1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 * 21 */ 22 23 /* 24 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 /* 29 * HISTORY 30 * 5-28-96 Jerry Yeung Three phase set protocol(ThreePhase) 31 */ 32 33 #ifndef _SESSION_H_ 34 #define _SESSION_H_ 35 36 #pragma ident "%Z%%M% %I% %E% SMI" 37 38 typedef enum _Phase { PHASE_1=1, PHASE_2, PHASE_3} Phase; 39 40 41 /***** GLOBAL CONSTANTS *****/ 42 43 /* states of a request */ 44 #define REQUEST_STARTED 1 45 #define REQUEST_COMPLETED 2 46 47 48 /***** GLOBAL TYPES *****/ 49 50 typedef struct _Agent_List { 51 struct _Agent_List *next; 52 struct _Agent *agent; 53 } Agent_List; 54 55 56 typedef struct _Request { 57 struct _Request *next_request; 58 59 struct _Session *session; 60 struct _Subtree *subtree; /* associated subtree */ 61 Agent_List *visited_agent_list; /* list of the agents visited so far */ 62 63 u_long request_id; 64 65 SNMP_pdu *pdu; /* SNMP request */ 66 67 u_long flags; /* cf below */ 68 69 int state; /* STARTED or COMPLETED */ 70 SNMP_pdu *response; /* response of the agent to the pdu */ 71 72 struct timeval time; /* time when the pdu was sent */ 73 struct timeval expire; /* time when the Request will timeout */ 74 } Request; 75 76 77 typedef struct _Session { 78 struct _Session *next_session; 79 80 u_long session_id; 81 82 Address address; /* the address of the SNMP application */ 83 84 SNMP_pdu *pdu; /* the "original" SNMP request */ 85 86 int n_variables; /* number of variables in the */ 87 /* "original" SNMP request */ 88 89 u_long o_flags; /* cf below */ 90 u_long i_flags; /* cf below */ 91 92 struct _Request *first_request; /* the request list of the session */ 93 94 } Session; 95 96 /* Three Phase */ 97 typedef struct _Three_Phase { 98 SNMP_pdu *origin_pdu; 99 SNMP_pdu *cur_pdu; 100 Phase state; 101 SNMP_variable *variable; 102 Session* session; 103 } Three_Phase; 104 105 106 107 /* explanation for the flags: */ 108 /* -------------------------- */ 109 /* */ 110 /* Each bit in a flags corresponds to a variable */ 111 /* in the "original" SNMP request. */ 112 /* For example, the o_flag 0x7 in the Session means */ 113 /* that the "original" SNMP request contains 3 */ 114 /* variables, the flags 0x5 of the Request 0 means that */ 115 /* this Request handles the 1st and the 3rd */ 116 /* variable of the "original" SNMP request, the flags */ 117 /* 0x2 of the Request 1 means that this Request */ 118 /* handles the 2nd variable of the "original" SNMP */ 119 /* request. When a Request is completed, its flags */ 120 /* are ORed with the i_flags of its Session, so as soon */ 121 /* as o_flags == i_flags, we known that all the Requests*/ 122 /* are completed and we start to compute the response */ 123 /* of the "original" SNMP request. */ 124 125 126 /***** GLOBAL FUNCTIONS *****/ 127 128 extern void trace_sessions(); 129 130 /* session_list_delete() will delete the whole session list */ 131 extern void session_list_delete(); 132 133 extern void session_dispatch(); 134 extern void session_read(); 135 136 extern void session_select_info(struct timeval *tv); 137 extern void session_timeout(); 138 139 extern int any_outstanding_session(); 140 141 extern void session_close(Session *session); 142 extern void session_free(Session *session); 143 extern void request_list_free(Request *request_list); 144 extern void request_free(Request *request); 145 146 #endif /* _SESSION_H_ */ 147 148