@@ -60,7 +60,6 @@ static inline uint32_t alushim_get_interceptid(alushimhdr_t *aluhdr) {
6060static inline int alushim_get_direction (alushimhdr_t * aluhdr ) {
6161
6262 uint32_t intid = ntohl (aluhdr -> interceptid );
63-
6463 /* In ETSI, 0 = from target, 1 = to target, 2 = unknown */
6564 /* In ALU, 0 = ingress (from subscriber), 1 = egress (to subscriber) */
6665
@@ -83,38 +82,24 @@ static inline int alushim_get_direction(alushimhdr_t *aluhdr) {
8382 return 2 ;
8483}
8584
86- int check_alu_intercept ( colthread_local_t * loc ,
87- libtrace_packet_t * packet , packet_info_t * pinfo ,
88- coreserver_t * alusources , vendmirror_intercept_list_t * aluints ) {
85+ uint8_t * decode_alushim_from_udp_payload ( uint8_t * payload , uint32_t plen ,
86+ uint32_t * cin , uint8_t * dir , uint32_t * shimintid , uint32_t * bodylen ) {
87+
8988
90- coreserver_t * cs ;
91- vendmirror_intercept_t * alu , * tmp ;
92- vendmirror_intercept_list_t * vmilist ;
9389 uint16_t ethertype ;
9490 alushimhdr_t * aluhdr = NULL ;
95- uint32_t rem = 0 , shimintid , cin ;
9691 void * l3 , * l2 ;
92+ uint32_t rem = plen ;
9793
98- if ((cs = match_packet_to_coreserver (alusources , pinfo , 1 )) == NULL ) {
99- return 0 ;
100- }
101-
102- /* Extract the intercept ID, direction and session ID */
103- aluhdr = (alushimhdr_t * )get_udp_payload (packet , & rem , NULL , NULL );
94+ aluhdr = (alushimhdr_t * )payload ;
10495 if (!aluhdr || rem < sizeof (alushimhdr_t )) {
105- return 0 ;
96+ return NULL ;
10697 }
10798
108- shimintid = alushim_get_interceptid (aluhdr );
109-
110- /* See if the intercept ID is in our set of intercepts */
111- HASH_FIND (hh , aluints , & shimintid , sizeof (shimintid ), vmilist );
112- if (vmilist == NULL ) {
113- return 0 ;
114- }
99+ * shimintid = alushim_get_interceptid (aluhdr );
115100
116101 /* Strip the extra headers + shim */
117- l2 = ((char * )aluhdr ) + sizeof (alushimhdr_t );
102+ l2 = ((uint8_t * )aluhdr ) + sizeof (alushimhdr_t );
118103 rem -= sizeof (alushimhdr_t );
119104
120105 /* TODO add support for layer 3 only intercepts? */
@@ -139,28 +124,67 @@ int check_alu_intercept(colthread_local_t *loc,
139124 continue ;
140125 case TRACE_ETHERTYPE_ARP :
141126 /* Probably shouldn't be intercepting ARP */
142- return 0 ;
127+ return NULL ;
143128 case TRACE_ETHERTYPE_IP :
144129 case TRACE_ETHERTYPE_IPV6 :
145130 break ;
146131 default :
147- return 0 ;
132+ return NULL ;
148133 }
149134 break ;
150135 }
151136
152137 if (!l3 || rem == 0 ) {
153138 logger (LOG_INFO ,
154- "Warning: unable to find IP header of ALU-intercepted packet from mirror (ID: %u)" ,
155- cs -> serverkey , shimintid );
156- return -1 ;
139+ "Warning: unable to find IP header of ALU-intercepted packet from mirror (ID: %u)" , * shimintid );
140+ return NULL ;
141+ }
142+
143+ /* Use the session ID from the shim as the CIN */
144+ * cin = ntohl (aluhdr -> sessionid );
145+ * dir = alushim_get_direction (aluhdr );
146+ * bodylen = rem ;
147+ return l3 ;
148+ }
149+
150+ int check_alu_intercept (colthread_local_t * loc ,
151+ libtrace_packet_t * packet , packet_info_t * pinfo ,
152+ coreserver_t * alusources , vendmirror_intercept_list_t * aluints ) {
153+
154+ coreserver_t * cs ;
155+ vendmirror_intercept_t * alu , * tmp ;
156+ vendmirror_intercept_list_t * vmilist ;
157+ uint32_t rem = 0 , shimintid , cin , bodylen ;
158+ void * l3 ;
159+ uint8_t * payload = NULL ;
160+ uint8_t direction ;
161+
162+ if ((cs = match_packet_to_coreserver (alusources , pinfo , 1 )) == NULL ) {
163+ return 0 ;
164+ }
165+
166+ /* Extract the intercept ID, direction and session ID */
167+ payload = get_udp_payload (packet , & rem , NULL , NULL );
168+ if (!payload || rem < sizeof (alushimhdr_t )) {
169+ return 0 ;
170+ }
171+
172+ l3 = decode_alushim_from_udp_payload (payload , rem , & cin , & direction ,
173+ & shimintid , & bodylen );
174+ if (!l3 ) {
175+ return 0 ;
176+ }
177+
178+ /* See if the intercept ID is in our set of intercepts */
179+ HASH_FIND (hh , aluints , & shimintid , sizeof (shimintid ), vmilist );
180+ if (vmilist == NULL ) {
181+ return 0 ;
157182 }
158183
159184 /* Direction 0 = ingress (i.e. coming from the subscriber) */
160185
161186 /* Use the session ID from the shim as the CIN */
162187 /* TODO double check that this will be available in the RADIUS stream */
163- cin = ntohl (aluhdr -> sessionid );
164188
165189 HASH_ITER (hh , vmilist -> intercepts , alu , tmp ) {
166190 if (pinfo -> tv .tv_sec < alu -> common .tostart_time ) {
@@ -173,8 +197,7 @@ int check_alu_intercept(colthread_local_t *loc,
173197
174198 /* Create an appropriate IPCC and export it */
175199 if (push_vendor_mirrored_ipcc_job (loc -> zmq_pubsocks [0 ], & (alu -> common ),
176- trace_get_timeval (packet ), cin , alushim_get_direction (aluhdr ),
177- l3 , rem ) == 0 ) {
200+ trace_get_timeval (packet ), cin , direction , l3 , bodylen ) == 0 ) {
178201 /* for some reason, we failed to create or send the IPCC to
179202 * the sequencing thread? */
180203
0 commit comments