3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
/*****************************************************************************
25
* Filename: InkMgmtAPI.cc
26
* Purpose: This file implements all traffic server management functions.
28
* Created by: Lan Tran
31
***************************************************************************/
36
#include "INKMgmtAPI.h"
37
#include "CfgContextManager.h"
38
#include "CfgContextImpl.h"
39
#include "CfgContextUtils.h"
41
#include "CoreAPIShared.h"
43
#include "TextBuffer.h"
45
// forward declarations
46
void init_pdss_format(INKPdSsFormat * info);
49
/***************************************************************************
50
* API Memory Management
51
***************************************************************************/
53
_INKmalloc(unsigned int size, const char *path)
58
return _xmalloc(size, path);
63
_INKrealloc(void *ptr, unsigned int size, const char *path)
66
return xrealloc(ptr, size);
68
return _xrealloc(ptr, size, path);
73
_INKstrdup(const char *str, int length, const char *path)
76
return xstrndup(str, length);
78
return _xstrdup(str, length, path);
93
/***************************************************************************
94
* API Helper Functions for Data Carrier Structures
95
***************************************************************************/
97
/*--- INKList operations -------------------------------------------------*/
101
return (void *) create_queue();
104
/* NOTE: The List must be EMPTY */
106
INKListDestroy(INKList l)
111
delete_queue((LLQ *) l);
116
INKListEnqueue(INKList l, void *data)
120
ink_assert(l && data);
122
return INK_ERR_PARAMS;
124
ret = enqueue((LLQ *) l, data); /* returns TRUE=1 or FALSE=0 */
133
INKListDequeue(INKList l)
136
if (!l || queue_is_empty((LLQ *) l))
139
return dequeue((LLQ *) l);
143
INKListIsEmpty(INKList l)
149
return true; // list doesn't exist, so it's empty
151
ret = queue_is_empty((LLQ *) l); /* returns 0 if empty, non-zero if not empty */
152
if (ret == 0) { /* empty */
160
INKListLen(INKList l)
166
return queue_len((LLQ *) l);
170
INKListIsValid(INKList l)
178
len = queue_len((LLQ *) l);
179
for (i = 0; i < len; i++) {
180
ele = (void *) dequeue((LLQ *) l);
183
enqueue((LLQ *) l, ele);
188
/*--- INKIpAddrList operations -------------------------------------------------*/
190
INKIpAddrListCreate(void)
192
return (void *) create_queue(); /* this queue will be a list of IpAddrEle* */
196
INKIpAddrListDestroy(INKIpAddrList ip_addrl)
198
INKIpAddrEle *ipaddr_ele;
204
/* dequeue each element and free it;
205
currently, an element can only be an INKIpAddrEle
206
or it can be an INKIpAddr ?? */
207
while (!queue_is_empty((LLQ *) ip_addrl)) {
208
ipaddr_ele = (INKIpAddrEle *) dequeue((LLQ *) ip_addrl);
213
INKIpAddrEleDestroy(ipaddr_ele);
216
/* we have removed everything on the list so free list */
217
delete_queue((LLQ *) ip_addrl);
222
INKIpAddrListEnqueue(INKIpAddrList ip_addrl, INKIpAddrEle * ip_addr)
226
ink_assert(ip_addrl && ip_addr);
227
if (!ip_addrl || !ip_addr)
228
return INK_ERR_PARAMS;
230
ret = enqueue((LLQ *) ip_addrl, ip_addr);
239
/* The the INKIpAddrEle returned is actually removed from the end of list */
240
inkapi INKIpAddrEle *
241
INKIpAddrListDequeue(INKIpAddrList ip_addrl)
243
ink_assert(ip_addrl);
244
if (!ip_addrl || queue_is_empty((LLQ *) ip_addrl))
247
return (INKIpAddrEle *) dequeue((LLQ *) ip_addrl);
252
INKIpAddrListLen(INKIpAddrList ip_addrl)
254
ink_assert(ip_addrl);
258
return queue_len((LLQ *) ip_addrl);
262
INKIpAddrListIsEmpty(INKIpAddrList ip_addrl)
264
ink_assert(ip_addrl);
268
return queue_is_empty((LLQ *) ip_addrl);
271
// returns false if any of the IpAddrEle is not an valid IP address by making
272
// use of ccu_checkIpAddrEle; if return false, the ip's may be reordered
273
// from the original list
275
INKIpAddrListIsValid(INKIpAddrList ip_addrl)
283
len = queue_len((LLQ *) ip_addrl);
284
for (i = 0; i < len; i++) {
285
ele = (INKIpAddrEle *) dequeue((LLQ *) ip_addrl);
286
if (!ccu_checkIpAddrEle(ele)) {
287
enqueue((LLQ *) ip_addrl, ele);
290
enqueue((LLQ *) ip_addrl, ele);
295
/*--- INKPortList operations ----------------------------------------------*/
299
return (void *) create_queue(); /* this queue will be a list of INKPortEle* */
303
INKPortListDestroy(INKPortList portl)
305
INKPortEle *port_ele;
310
// dequeue each element and free it
311
while (!queue_is_empty((LLQ *) portl)) {
312
port_ele = (INKPortEle *) dequeue((LLQ *) portl);
317
INKPortEleDestroy(port_ele);
320
/* we have removed everything on the list so free list */
321
delete_queue((LLQ *) portl);
326
INKPortListEnqueue(INKPortList portl, INKPortEle * port)
330
ink_assert(portl && port);
332
return INK_ERR_PARAMS;
334
ret = enqueue((LLQ *) portl, port); /* returns TRUE=1 or FALSE=0 */
343
INKPortListDequeue(INKPortList portl)
346
if (!portl || queue_is_empty((LLQ *) portl))
349
return (INKPortEle *) dequeue((LLQ *) portl);
353
INKPortListLen(INKPortList portl)
359
return queue_len((LLQ *) portl);
363
INKPortListIsEmpty(INKPortList portl)
369
return queue_is_empty((LLQ *) portl);
372
// returns false if any of the PortEle's has a port_a <= 0;
373
// if returns false, then will return the entire port list
374
// intact, although the ports may not be ordered in the same way
376
INKPortListIsValid(INKPortList portl)
384
len = queue_len((LLQ *) portl);
385
for (i = 0; i < len; i++) {
386
ele = (INKPortEle *) dequeue((LLQ *) portl);
387
if (!ccu_checkPortEle(ele)) {
388
enqueue((LLQ *) portl, ele);
391
enqueue((LLQ *) portl, ele);
397
/*--- INKDomainList operations -----------------------------------------*/
399
INKDomainListCreate()
401
return (void *) create_queue(); /* this queue will be a list of char* */
405
INKDomainListDestroy(INKDomainList domainl)
413
/* dequeue each element and free it */
414
while (!queue_is_empty((LLQ *) domainl)) {
415
domain = (INKDomain *) dequeue((LLQ *) domainl);
420
INKDomainDestroy(domain);
423
delete_queue((LLQ *) domainl);
427
INKDomainListEnqueue(INKDomainList domainl, INKDomain * domain)
431
ink_assert(domainl && domain);
432
if (!domainl || !domain)
433
return INK_ERR_PARAMS;
435
ret = enqueue((LLQ *) domainl, domain); /* returns TRUE=1 or FALSE=0 */
444
INKDomainListDequeue(INKDomainList domainl)
447
if (!domainl || queue_is_empty((LLQ *) domainl))
450
return (INKDomain *) dequeue((LLQ *) domainl);
454
INKDomainListIsEmpty(INKDomainList domainl)
460
return queue_is_empty((LLQ *) domainl);
464
INKDomainListLen(INKDomainList domainl)
470
return queue_len((LLQ *) domainl);
473
// returns false if encounter a NULL hostname and ip
475
INKDomainListIsValid(INKDomainList domainl)
483
len = queue_len((LLQ *) domainl);
484
for (i = 0; i < len; i++) {
485
dom = (INKDomain *) dequeue((LLQ *) domainl);
489
if (!dom->domain_val) {
492
enqueue((LLQ *) domainl, dom);
498
/*--- INKStringList operations --------------------------------------*/
500
INKStringListCreate()
502
return (void *) create_queue(); /* this queue will be a list of char* */
505
/* usually, must be an empty list before destroying*/
507
INKStringListDestroy(INKStringList strl)
515
/* dequeue each element and free it */
516
while (!queue_is_empty((LLQ *) strl)) {
517
str = (char *) dequeue((LLQ *) strl);
525
delete_queue((LLQ *) strl);
529
INKStringListEnqueue(INKStringList strl, char *str)
533
ink_assert(strl && str);
535
return INK_ERR_PARAMS;
537
ret = enqueue((LLQ *) strl, str); /* returns TRUE=1 or FALSE=0 */
546
INKStringListDequeue(INKStringList strl)
549
if (!strl || queue_is_empty((LLQ *) strl))
552
return (char *) dequeue((LLQ *) strl);
556
INKStringListIsEmpty(INKStringList strl)
562
return queue_is_empty((LLQ *) strl);
566
INKStringListLen(INKStringList strl)
572
return queue_len((LLQ *) strl);
575
// returns false if any element is NULL string
577
INKStringListIsValid(INKStringList strl)
585
len = queue_len((LLQ *) strl);
586
for (i = 0; i < len; i++) {
587
str = (char *) dequeue((LLQ *) strl);
590
enqueue((LLQ *) strl, str);
595
/*--- INKIntList operations --------------------------------------*/
599
return (void *) create_queue(); /* this queue will be a list of int* */
602
/* usually, must be an empty list before destroying*/
604
INKIntListDestroy(INKIntList intl)
611
/* dequeue each element and free it */
612
while (!queue_is_empty((LLQ *) intl)) {
613
iPtr = (int *) dequeue((LLQ *) intl);
621
delete_queue((LLQ *) intl);
626
INKIntListEnqueue(INKIntList intl, int *elem)
630
ink_assert(intl && elem);
632
return INK_ERR_PARAMS;
634
ret = enqueue((LLQ *) intl, elem); /* returns TRUE=1 or FALSE=0 */
643
INKIntListDequeue(INKIntList intl)
646
if (!intl || queue_is_empty((LLQ *) intl))
649
return (int *) dequeue((LLQ *) intl);
653
INKIntListIsEmpty(INKIntList intl)
659
return queue_is_empty((LLQ *) intl);
663
INKIntListLen(INKIntList intl)
669
return queue_len((LLQ *) intl);
673
INKIntListIsValid(INKIntList intl, int min, int max)
678
for (unsigned long i = 0; i < queue_len((LLQ *) intl); i++) {
679
int *item = (int *) dequeue((LLQ *) intl);
686
enqueue((LLQ *) intl, item);
692
// helper fn that sets default values for the info passed in
694
init_pdss_format(INKPdSsFormat * info)
696
info->pd_type = INK_PD_UNDEFINED;
698
info->sec_spec.active = 0;
699
info->sec_spec.time.hour_a = 0;
700
info->sec_spec.time.min_a = 0;
701
info->sec_spec.time.hour_b = 0;
702
info->sec_spec.time.min_b = 0;
703
info->sec_spec.src_ip = INK_INVALID_IP_ADDR;
704
info->sec_spec.prefix = NULL;
705
info->sec_spec.suffix = NULL;
706
info->sec_spec.port = INK_INVALID_PORT;
707
info->sec_spec.method = INK_METHOD_UNDEFINED;
708
info->sec_spec.scheme = INK_SCHEME_UNDEFINED;
711
/*--- allocate/deallocate operations --------------------------------------*/
716
event = (INKEvent *) xmalloc(sizeof(INKEvent));
722
event->description = NULL;
723
event->priority = INK_EVENT_PRIORITY_UNDEFINED;
729
INKEventDestroy(INKEvent * event)
734
if (event->description)
735
xfree(event->description);
741
inkapi INKRecordEle *
742
INKRecordEleCreate(void)
745
ele = (INKRecordEle *) xmalloc(sizeof(INKRecordEle));
749
ele->rec_name = NULL;
750
ele->rec_type = INK_REC_UNDEFINED;
753
//ele->counter_val = -1;
754
//ele->float_val = -1;
755
//ele->string_val = NULL;
761
INKRecordEleDestroy(INKRecordEle * ele)
765
xfree(ele->rec_name);
766
if (ele->rec_type == INK_REC_STRING && ele->string_val)
767
xfree(ele->string_val);
773
inkapi INKIpAddrEle *
774
INKIpAddrEleCreate(void)
778
ele = (INKIpAddrEle *) xmalloc(sizeof(INKIpAddrEle));
782
/* set default values */
783
ele->type = INK_IP_UNDEFINED;
784
ele->ip_a = INK_INVALID_IP_ADDR;
785
ele->cidr_a = INK_INVALID_IP_CIDR;
786
ele->port_a = INK_INVALID_PORT;
787
ele->ip_b = INK_INVALID_IP_ADDR;
788
ele->cidr_b = INK_INVALID_IP_CIDR;
789
ele->port_b = INK_INVALID_PORT;
794
INKIpAddrEleDestroy(INKIpAddrEle * ele)
808
INKPortEleCreate(void)
812
ele = (INKPortEle *) xmalloc(sizeof(INKPortEle));
816
ele->port_a = INK_INVALID_PORT;
817
ele->port_b = INK_INVALID_PORT;
823
INKPortEleDestroy(INKPortEle * ele)
835
ele = (INKDomain *) xmalloc(sizeof(INKDomain));
839
ele->domain_val = NULL;
840
ele->port = INK_INVALID_PORT;
846
INKDomainDestroy(INKDomain * ele)
849
// this is okay because INKIpAddr is also a char*
851
xfree(ele->domain_val);
861
sec_spec = (INKSspec *) xmalloc(sizeof(INKSspec));
866
sec_spec->active = 0;
867
(sec_spec->time).hour_a = 0;
868
(sec_spec->time).min_a = 0;
869
(sec_spec->time).hour_b = 0;
870
(sec_spec->time).min_b = 0;
871
sec_spec->src_ip = INK_INVALID_IP_ADDR;
872
sec_spec->prefix = NULL;
873
sec_spec->suffix = NULL;
874
sec_spec->port = NULL;
875
sec_spec->method = INK_METHOD_UNDEFINED;
876
sec_spec->scheme = INK_SCHEME_UNDEFINED;
881
INKSspecDestroy(INKSspec * ele)
889
INKPortEleDestroy(ele->port);
895
inkapi INKPdSsFormat *
896
INKPdSsFormatCreate(void)
900
ele = (INKPdSsFormat *) xmalloc(sizeof(INKPdSsFormat));
904
/* should set default values here */
905
ele->pd_type = INK_PD_UNDEFINED;
908
ele->sec_spec.active = 0;
909
(ele->sec_spec.time).hour_a = -1;
910
(ele->sec_spec.time).min_a = -1;
911
(ele->sec_spec.time).hour_b = -1;
912
(ele->sec_spec.time).min_b = -1;
913
ele->sec_spec.src_ip = INK_INVALID_IP_ADDR;
914
ele->sec_spec.prefix = NULL;
915
ele->sec_spec.suffix = NULL;
916
ele->sec_spec.port = NULL;
917
ele->sec_spec.method = INK_METHOD_UNDEFINED;
918
ele->sec_spec.scheme = INK_SCHEME_UNDEFINED;
924
INKPdSsFormatDestroy(INKPdSsFormat * ele)
929
if (ele->sec_spec.src_ip)
930
xfree(ele->sec_spec.src_ip);
931
if (ele->sec_spec.prefix)
932
xfree(ele->sec_spec.prefix);
933
if (ele->sec_spec.suffix)
934
xfree(ele->sec_spec.suffix);
935
if (ele->sec_spec.port)
936
INKPortEleDestroy(ele->sec_spec.port);
941
/*-------------------------------------------------------------
943
*-------------------------------------------------------------*/
944
inkapi INKAdminAccessEle *
945
INKAdminAccessEleCreate()
947
INKAdminAccessEle *ele;
949
ele = (INKAdminAccessEle *) xmalloc(sizeof(INKAdminAccessEle));
953
ele->cfg_ele.type = INK_ADMIN_ACCESS;
954
ele->cfg_ele.error = INK_ERR_OKAY;
956
ele->password = NULL;
957
ele->access = INK_ACCESS_UNDEFINED;
963
INKAdminAccessEleDestroy(INKAdminAccessEle * ele)
969
xfree(ele->password);
976
/*-------------------------------------------------------------
978
*-------------------------------------------------------------*/
980
INKCacheEleCreate(INKRuleTypeT type)
984
if (type != INK_CACHE_NEVER &&
985
type != INK_CACHE_IGNORE_NO_CACHE &&
986
type != INK_CACHE_IGNORE_CLIENT_NO_CACHE &&
987
type != INK_CACHE_IGNORE_SERVER_NO_CACHE &&
988
type != INK_CACHE_PIN_IN_CACHE &&
989
type != INK_CACHE_REVALIDATE &&
990
type != INK_CACHE_TTL_IN_CACHE && type != INK_CACHE_AUTH_CONTENT && type != INK_TYPE_UNDEFINED)
991
return NULL; // invalid type
993
ele = (INKCacheEle *) xmalloc(sizeof(INKCacheEle));
998
ele->cfg_ele.type = type;
999
ele->cfg_ele.error = INK_ERR_OKAY;
1000
init_pdss_format(&(ele->cache_info));
1001
ele->time_period.d = 0;
1002
ele->time_period.h = 0;
1003
ele->time_period.m = 0;
1004
ele->time_period.s = 0;
1010
INKCacheEleDestroy(INKCacheEle * ele)
1013
INKPdSsFormatDestroy(&(ele->cache_info));
1019
/*-------------------------------------------------------------
1021
*-------------------------------------------------------------*/
1022
// FIXME: for now use defaults specified in feature spec; the
1023
// defaults though are configurable as records, so should use
1024
// records values instead
1025
inkapi INKCongestionEle *
1026
INKCongestionEleCreate()
1028
INKCongestionEle *ele;
1030
ele = (INKCongestionEle *) xmalloc(sizeof(INKCongestionEle));
1035
ele->cfg_ele.type = INK_CONGESTION;
1036
ele->cfg_ele.error = INK_ERR_OKAY;
1037
//init_pdss_format(&(ele->congestion_info));
1038
ele->pd_type = INK_PD_UNDEFINED;
1041
ele->port = INK_INVALID_PORT;
1042
ele->scheme = INK_HTTP_CONGEST_PER_IP;
1043
ele->max_connection_failures = 5;
1044
ele->fail_window = 120;
1045
ele->proxy_retry_interval = 10;
1046
ele->client_wait_interval = 300;
1047
ele->wait_interval_alpha = 30;
1048
ele->live_os_conn_timeout = 60;
1049
ele->live_os_conn_retries = 2;
1050
ele->dead_os_conn_timeout = 15;
1051
ele->dead_os_conn_retries = 1;
1052
ele->max_connection = -1;
1053
ele->error_page_uri = xstrdup("congestion#retryAfter");
1059
INKCongestionEleDestroy(INKCongestionEle * ele)
1066
if (ele->error_page_uri)
1067
xfree(ele->error_page_uri);
1074
/*-------------------------------------------------------------
1076
*-------------------------------------------------------------*/
1077
inkapi INKHostingEle *
1078
INKHostingEleCreate()
1082
ele = (INKHostingEle *) xmalloc(sizeof(INKHostingEle));
1086
ele->cfg_ele.type = INK_HOSTING;
1087
ele->cfg_ele.error = INK_ERR_OKAY;
1088
ele->pd_type = INK_PD_UNDEFINED;
1090
ele->partitions = INK_INVALID_LIST;
1096
INKHostingEleDestroy(INKHostingEle * ele)
1101
if (ele->partitions)
1102
INKIntListDestroy(ele->partitions);
1108
/*-------------------------------------------------------------
1110
*-------------------------------------------------------------*/
1116
ele = (INKIcpEle *) xmalloc(sizeof(INKIcpEle));
1121
ele->cfg_ele.type = INK_ICP;
1122
ele->cfg_ele.error = INK_ERR_OKAY;
1123
ele->peer_hostname = NULL;
1124
ele->peer_host_ip_addr = INK_INVALID_IP_ADDR;
1125
ele->peer_type = INK_ICP_UNDEFINED;
1126
ele->peer_proxy_port = INK_INVALID_PORT;
1127
ele->peer_icp_port = INK_INVALID_PORT;
1128
ele->is_multicast = FALSE;
1129
ele->mc_ip_addr = INK_INVALID_IP_ADDR;
1130
ele->mc_ttl = INK_MC_TTL_SINGLE_SUBNET; // default value
1137
INKIcpEleDestroy(INKIcpEle * ele)
1140
if (ele->peer_hostname)
1141
xfree(ele->peer_hostname);
1142
if (ele->peer_host_ip_addr)
1143
xfree(ele->peer_host_ip_addr);
1144
if (ele->mc_ip_addr)
1145
xfree(ele->mc_ip_addr);
1151
/*-------------------------------------------------------------
1153
*-------------------------------------------------------------*/
1154
inkapi INKIpAllowEle *
1155
INKIpAllowEleCreate()
1160
ele = (INKIpAllowEle *) xmalloc(sizeof(INKIpAllowEle));
1164
ele->cfg_ele.type = INK_IP_ALLOW;
1165
ele->cfg_ele.error = INK_ERR_OKAY;
1166
ele->src_ip_addr = INK_INVALID_IP_ADDR;
1167
ele->action = INK_IP_ALLOW_UNDEFINED;
1173
INKIpAllowEleDestroy(INKIpAllowEle * ele)
1176
if (ele->src_ip_addr)
1177
INKIpAddrEleDestroy(ele->src_ip_addr);
1185
/*-------------------------------------------------------------
1187
*-------------------------------------------------------------*/
1188
inkapi INKLogFilterEle *
1189
INKLogFilterEleCreate()
1191
INKLogFilterEle *ele;
1193
ele = (INKLogFilterEle *) xmalloc(sizeof(INKLogFilterEle));
1197
ele->cfg_ele.type = INK_LOG_FILTER;
1198
ele->cfg_ele.error = INK_ERR_OKAY;
1199
ele->action = INK_LOG_FILT_UNDEFINED;
1200
ele->filter_name = NULL;
1201
ele->log_field = NULL;
1202
ele->compare_op = INK_LOG_COND_UNDEFINED;
1203
ele->compare_str = NULL;
1204
ele->compare_int = -1;
1209
INKLogFilterEleDestroy(INKLogFilterEle * ele)
1212
if (ele->filter_name)
1213
xfree(ele->filter_name);
1215
xfree(ele->log_field);
1216
if (ele->compare_str)
1217
xfree(ele->compare_str);
1223
/*-------------------------------------------------------------
1225
*-------------------------------------------------------------*/
1226
inkapi INKLogFormatEle *
1227
INKLogFormatEleCreate()
1229
INKLogFormatEle *ele;
1231
ele = (INKLogFormatEle *) xmalloc(sizeof(INKLogFormatEle));
1235
ele->cfg_ele.type = INK_LOG_FORMAT;
1236
ele->cfg_ele.error = INK_ERR_OKAY;
1239
ele->aggregate_interval_secs = 0;
1245
INKLogFormatEleDestroy(INKLogFormatEle * ele)
1257
/*-------------------------------------------------------------
1259
*-------------------------------------------------------------*/
1260
inkapi INKLogObjectEle *
1261
INKLogObjectEleCreate()
1263
INKLogObjectEle *ele;
1265
ele = (INKLogObjectEle *) xmalloc(sizeof(INKLogObjectEle));
1269
ele->cfg_ele.type = INK_LOG_OBJECT;
1270
ele->cfg_ele.error = INK_ERR_OKAY;
1271
ele->format_name = NULL;
1272
ele->file_name = NULL;
1273
ele->log_mode = INK_LOG_MODE_UNDEFINED;
1274
ele->collation_hosts = INK_INVALID_LIST;
1275
ele->filters = INK_INVALID_LIST;
1276
ele->protocols = INK_INVALID_LIST;
1277
ele->server_hosts = INK_INVALID_LIST;
1283
INKLogObjectEleDestroy(INKLogObjectEle * ele)
1286
if (ele->format_name)
1287
xfree(ele->format_name);
1289
xfree(ele->file_name);
1290
if (ele->collation_hosts)
1291
INKDomainListDestroy(ele->collation_hosts);
1293
INKStringListDestroy(ele->filters);
1295
INKStringListDestroy(ele->protocols);
1296
if (ele->server_hosts)
1297
INKStringListDestroy(ele->server_hosts);
1303
/*-------------------------------------------------------------
1305
*-------------------------------------------------------------*/
1306
inkapi INKMgmtAllowEle *
1307
INKMgmtAllowEleCreate()
1310
INKMgmtAllowEle *ele;
1312
ele = (INKMgmtAllowEle *) xmalloc(sizeof(INKMgmtAllowEle));
1316
ele->cfg_ele.type = INK_MGMT_ALLOW;
1317
ele->cfg_ele.error = INK_ERR_OKAY;
1318
ele->src_ip_addr = INK_INVALID_IP_ADDR;
1319
ele->action = INK_MGMT_ALLOW_UNDEFINED;
1325
INKMgmtAllowEleDestroy(INKMgmtAllowEle * ele)
1328
if (ele->src_ip_addr)
1329
INKIpAddrEleDestroy(ele->src_ip_addr);
1337
/*-------------------------------------------------------------
1338
* INKParentProxyEleCreate
1339
*-------------------------------------------------------------*/
1340
inkapi INKParentProxyEle *
1341
INKParentProxyEleCreate(INKRuleTypeT type)
1343
INKParentProxyEle *ele;
1345
if (type != INK_PP_PARENT && type != INK_PP_GO_DIRECT && type != INK_TYPE_UNDEFINED)
1348
ele = (INKParentProxyEle *) xmalloc(sizeof(INKParentProxyEle));
1352
ele->cfg_ele.type = type;
1353
ele->cfg_ele.error = INK_ERR_OKAY;
1354
init_pdss_format(&(ele->parent_info));
1355
ele->rr = INK_RR_NONE;
1356
ele->proxy_list = INK_INVALID_LIST;
1357
ele->direct = false;
1363
INKParentProxyEleDestroy(INKParentProxyEle * ele)
1366
INKPdSsFormatDestroy(&(ele->parent_info));
1367
if (ele->proxy_list)
1368
INKDomainListDestroy(ele->proxy_list);
1375
/*-------------------------------------------------------------
1377
*-------------------------------------------------------------*/
1378
inkapi INKPartitionEle *
1379
INKPartitionEleCreate()
1381
INKPartitionEle *ele;
1383
ele = (INKPartitionEle *) xmalloc(sizeof(INKPartitionEle));
1387
ele->cfg_ele.type = INK_PARTITION;
1388
ele->cfg_ele.error = INK_ERR_OKAY;
1389
ele->partition_num = 0;
1390
ele->scheme = INK_PARTITION_UNDEFINED;
1391
ele->partition_size = 0;
1392
ele->size_format = INK_SIZE_FMT_UNDEFINED;
1398
INKPartitionEleDestroy(INKPartitionEle * ele)
1406
/*-------------------------------------------------------------
1408
*-------------------------------------------------------------*/
1409
inkapi INKPluginEle *
1410
INKPluginEleCreate()
1414
ele = (INKPluginEle *) xmalloc(sizeof(INKPluginEle));
1418
ele->cfg_ele.type = INK_PLUGIN;
1419
ele->cfg_ele.error = INK_ERR_OKAY;
1421
ele->args = INK_INVALID_LIST;
1427
INKPluginEleDestroy(INKPluginEle * ele)
1433
INKStringListDestroy(ele->args);
1439
/*-------------------------------------------------------------
1441
*-------------------------------------------------------------*/
1443
INKRemapEleCreate(INKRuleTypeT type)
1447
if (type != INK_REMAP_MAP &&
1448
type != INK_REMAP_REVERSE_MAP &&
1449
type != INK_REMAP_REDIRECT && type != INK_REMAP_REDIRECT_TEMP && type != INK_TYPE_UNDEFINED)
1452
ele = (INKRemapEle *) xmalloc(sizeof(INKRemapEle));
1456
ele->cfg_ele.type = type;
1457
ele->cfg_ele.error = INK_ERR_OKAY;
1459
ele->from_scheme = INK_SCHEME_UNDEFINED;
1460
ele->from_host = NULL;
1461
ele->from_port = INK_INVALID_PORT;
1462
ele->from_path_prefix = NULL;
1463
ele->to_scheme = INK_SCHEME_UNDEFINED;
1464
ele->to_host = NULL;
1465
ele->to_port = INK_INVALID_PORT;
1466
ele->to_path_prefix = NULL;
1472
INKRemapEleDestroy(INKRemapEle * ele)
1476
xfree(ele->from_host);
1477
if (ele->from_path_prefix)
1478
xfree(ele->from_path_prefix);
1480
xfree(ele->to_host);
1481
if (ele->to_path_prefix)
1482
xfree(ele->to_path_prefix);
1487
/*-------------------------------------------------------------
1489
*-------------------------------------------------------------*/
1491
INKSocksEleCreate(INKRuleTypeT type)
1494
ele = (INKSocksEle *) xmalloc(sizeof(INKSocksEle));
1498
ele->cfg_ele.type = type;
1499
ele->cfg_ele.error = INK_ERR_OKAY;
1500
ele->ip_addrs = INK_INVALID_LIST;
1501
ele->dest_ip_addr = INK_INVALID_IP_ADDR;
1502
ele->socks_servers = INK_INVALID_LIST;
1503
ele->rr = INK_RR_NONE;
1504
ele->username = NULL;
1505
ele->password = NULL;
1511
INKSocksEleDestroy(INKSocksEle * ele)
1515
INKIpAddrListDestroy(ele->ip_addrs);
1516
if (ele->dest_ip_addr)
1517
INKIpAddrEleDestroy(ele->dest_ip_addr);
1518
if (ele->socks_servers)
1519
INKDomainListDestroy(ele->socks_servers);
1521
xfree(ele->username);
1523
xfree(ele->password);
1528
/*-------------------------------------------------------------
1530
*-------------------------------------------------------------*/
1532
INKSplitDnsEleCreate()
1534
INKSplitDnsEle *ele;
1535
ele = (INKSplitDnsEle *) xmalloc(sizeof(INKSplitDnsEle));
1539
ele->cfg_ele.type = INK_SPLIT_DNS;
1540
ele->cfg_ele.error = INK_ERR_OKAY;
1541
ele->pd_type = INK_PD_UNDEFINED;
1543
ele->dns_servers_addrs = INK_INVALID_LIST;
1544
ele->def_domain = NULL;
1545
ele->search_list = INK_INVALID_LIST;
1551
INKSplitDnsEleDestroy(INKSplitDnsEle * ele)
1556
if (ele->dns_servers_addrs)
1557
INKDomainListDestroy(ele->dns_servers_addrs);
1558
if (ele->def_domain)
1559
xfree(ele->def_domain);
1560
if (ele->search_list)
1561
INKDomainListDestroy(ele->search_list);
1567
/*-------------------------------------------------------------
1569
*-------------------------------------------------------------*/
1571
INKStorageEleCreate()
1574
ele = (INKStorageEle *) xmalloc(sizeof(INKStorageEle));
1578
ele->cfg_ele.type = INK_STORAGE;
1579
ele->cfg_ele.error = INK_ERR_OKAY;
1580
ele->pathname = NULL;
1587
INKStorageEleDestroy(INKStorageEle * ele)
1591
xfree(ele->pathname);
1597
/*-------------------------------------------------------------
1599
*-------------------------------------------------------------*/
1601
INKUpdateEleCreate()
1604
ele = (INKUpdateEle *) xmalloc(sizeof(INKUpdateEle));
1608
ele->cfg_ele.type = INK_UPDATE_URL;
1609
ele->cfg_ele.error = INK_ERR_OKAY;
1611
ele->headers = INK_INVALID_LIST;
1612
ele->offset_hour = -1;
1614
ele->recursion_depth = 0;
1620
INKUpdateEleDestroy(INKUpdateEle * ele)
1626
INKStringListDestroy(ele->headers);
1632
/*-------------------------------------------------------------
1634
*-------------------------------------------------------------*/
1636
INKVirtIpAddrEleCreate()
1638
INKVirtIpAddrEle *ele;
1639
ele = (INKVirtIpAddrEle *) xmalloc(sizeof(INKVirtIpAddrEle));
1643
ele->cfg_ele.type = INK_VADDRS;
1644
ele->cfg_ele.error = INK_ERR_OKAY;
1647
ele->ip_addr = INK_INVALID_IP_ADDR;
1653
INKVirtIpAddrEleDestroy(INKVirtIpAddrEle * ele)
1659
xfree(ele->ip_addr);
1664
/***************************************************************************
1666
***************************************************************************/
1668
/*--- statistics operations ----------------------------------------------- */
1672
return StatsReset();
1675
/*--- variable operations ------------------------------------------------- */
1676
/* Call the CfgFileIO variable operations */
1679
INKRecordGet(char *rec_name, INKRecordEle * rec_val)
1681
return MgmtRecordGet(rec_name, rec_val);
1685
INKRecordGetInt(const char *rec_name, INKInt * int_val)
1687
INKError ret = INK_ERR_OKAY;
1689
INKRecordEle *ele = INKRecordEleCreate();
1690
ret = MgmtRecordGet(rec_name, ele);
1691
if (ret != INK_ERR_OKAY)
1694
*int_val = ele->int_val;
1697
INKRecordEleDestroy(ele);
1702
INKRecordGetCounter(const char *rec_name, INKCounter * counter_val)
1706
INKRecordEle *ele = INKRecordEleCreate();
1707
ret = MgmtRecordGet(rec_name, ele);
1708
if (ret != INK_ERR_OKAY)
1710
*counter_val = ele->counter_val;
1713
INKRecordEleDestroy(ele);
1718
INKRecordGetFloat(const char *rec_name, INKFloat * float_val)
1722
INKRecordEle *ele = INKRecordEleCreate();
1723
ret = MgmtRecordGet(rec_name, ele);
1724
if (ret != INK_ERR_OKAY)
1726
*float_val = ele->float_val;
1729
INKRecordEleDestroy(ele);
1734
INKRecordGetString(const char *rec_name, INKString *string_val)
1738
size_t str_size = 0;
1740
INKRecordEle *ele = INKRecordEleCreate();
1741
ret = MgmtRecordGet(rec_name, ele);
1742
if (ret != INK_ERR_OKAY)
1745
str_size = strlen(ele->string_val) + 1;
1746
str = (char *) xmalloc(sizeof(char) * str_size);
1748
return INK_ERR_SYS_CALL;
1749
ink_strncpy(str, ele->string_val, str_size);
1753
INKRecordEleDestroy(ele);
1758
/*-------------------------------------------------------------------------
1760
*-------------------------------------------------------------------------
1761
* Purpose: Retrieves list of record values specified in the rec_names list
1762
* Input: rec_names - list of record names to retrieve
1763
* rec_vals - queue of INKRecordEle* that correspons to rec_names
1764
* Output: If at any point, while retrieving one of the records there's a
1765
* a failure then the entire process is aborted, all the allocated
1766
* INKRecordEle's are deallocated and INK_ERR_FAIL is returned.
1767
* Note: rec_names is not freed; if function is successful, the rec_names
1768
* list is unchanged!
1770
* IS THIS FUNCTION AN ATOMIC TRANSACTION? Technically, all the variables
1771
* requested should refer to the same config file. But a lock is only
1772
* put on each variable it is looked up. Need to be able to lock
1773
* a file while retrieving all the requested records!
1777
INKRecordGetMlt(INKStringList rec_names, INKList rec_vals)
1784
if (!rec_names || !rec_vals)
1785
return INK_ERR_PARAMS;
1787
num_recs = queue_len((LLQ *) rec_names);
1788
for (i = 0; i < num_recs; i++) {
1789
rec_name = (char *) dequeue((LLQ *) rec_names); // remove name from list
1791
return INK_ERR_PARAMS; // NULL is invalid record name
1793
ele = INKRecordEleCreate();
1795
ret = MgmtRecordGet(rec_name, ele);
1796
enqueue((LLQ *) rec_names, rec_name); // return name to list
1798
if (ret != INK_ERR_OKAY) { // RecordGet failed
1799
// need to free all the ele's allocated by MgmtRecordGet so far
1800
INKRecordEleDestroy(ele);
1801
for (j = 0; j < i; j++) {
1802
ele = (INKRecordEle *) dequeue((LLQ *) rec_vals);
1804
INKRecordEleDestroy(ele);
1808
enqueue((LLQ *) rec_vals, ele); // all is good; add ele to end of list
1811
return INK_ERR_OKAY;
1816
INKRecordSet(const char *rec_name, const char *val, INKActionNeedT * action_need)
1818
return MgmtRecordSet(rec_name, val, action_need);
1823
INKRecordSetInt(const char *rec_name, INKInt int_val, INKActionNeedT * action_need)
1825
return MgmtRecordSetInt(rec_name, int_val, action_need);
1829
INKRecordSetCounter(const char *rec_name, INKCounter counter_val, INKActionNeedT * action_need)
1831
return MgmtRecordSetCounter(rec_name, counter_val, action_need);
1835
INKRecordSetFloat(const char *rec_name, INKFloat float_val, INKActionNeedT * action_need)
1837
return MgmtRecordSetFloat(rec_name, float_val, action_need);
1841
INKRecordSetString(const char *rec_name, const char *str_val, INKActionNeedT * action_need)
1843
return MgmtRecordSetString(rec_name, str_val, action_need);
1847
/*-------------------------------------------------------------------------
1849
*-------------------------------------------------------------------------
1850
* Basically iterates through each RecordEle in rec_list and calls the
1851
* appropriate "MgmtRecordSetxx" function for that record
1852
* Input: rec_list - queue of INKRecordEle*; each INKRecordEle* must have
1853
* a valid record name (remains unchanged on return)
1854
* Output: if there is an error during the setting of one of the variables then
1855
* will continue to try to set the other variables. Error response will
1856
* indicate though that not all set operations were successful.
1857
* INK_ERR_OKAY is returned if all the records are set successfully
1858
* Note: Determining the action needed is more complex b/c need to keep
1859
* track of which record change is the most drastic out of the group of
1860
* records; action_need will be set to the most severe action needed of
1861
* all the "Set" calls
1864
INKRecordSetMlt(INKList rec_list, INKActionNeedT * action_need)
1866
int num_recs, ret, i;
1868
INKError status = INK_ERR_OKAY;
1869
INKActionNeedT top_action_req = INK_ACTION_UNDEFINED;
1871
if (!rec_list || !action_need)
1872
return INK_ERR_PARAMS;
1874
num_recs = queue_len((LLQ *) rec_list);
1876
for (i = 0; i < num_recs; i++) {
1877
ele = (INKRecordEle *) dequeue((LLQ *) rec_list);
1879
switch (ele->rec_type) {
1881
ret = MgmtRecordSetInt(ele->rec_name, ele->int_val, action_need);
1883
case INK_REC_COUNTER:
1884
ret = MgmtRecordSetCounter(ele->rec_name, ele->counter_val, action_need);
1887
ret = MgmtRecordSetFloat(ele->rec_name, ele->float_val, action_need);
1889
case INK_REC_STRING:
1890
ret = MgmtRecordSetString(ele->rec_name, ele->string_val, action_need);
1895
}; /* end of switch (ele->rec_type) */
1896
if (ret != INK_ERR_OKAY)
1897
status = INK_ERR_FAIL;
1899
// keep track of most severe action; reset if needed
1900
// the INKACtionNeedT should be listed such that most severe actions have
1901
// a lower number (so most severe action == 0)
1902
if (*action_need < top_action_req) // a more severe action
1903
top_action_req = *action_need;
1905
enqueue((LLQ *) rec_list, ele);
1908
// set the action_need to be the most sever action needed of all the "set" calls
1909
*action_need = top_action_req;
1914
/*--- api initialization and shutdown -------------------------------------*/
1916
INKInit(const char *socket_path)
1918
return Init(socket_path);
1927
/*--- plugin initialization -----------------------------------------------*/
1929
INKPluginInit(int argc, const char *argv[])
1931
NOWARN_UNUSED(argc);
1932
NOWARN_UNUSED(argv);
1935
/*--- network operations --------------------------------------------------*/
1937
INKConnect(INKIpAddr ip_addr, int port)
1939
NOWARN_UNUSED(ip_addr);
1940
NOWARN_UNUSED(port);
1941
return INK_ERR_OKAY;
1944
INKDisconnectCbRegister(INKDisconnectFunc * func, void *data)
1946
NOWARN_UNUSED(func);
1947
NOWARN_UNUSED(data);
1948
return INK_ERR_OKAY;
1951
INKDisconnectRetrySet(int retries, int retry_sleep_msec)
1953
NOWARN_UNUSED(retries);
1954
NOWARN_UNUSED(retry_sleep_msec);
1955
return INK_ERR_OKAY;
1960
return INK_ERR_OKAY;
1963
/*--- control operations --------------------------------------------------*/
1964
/* NOTE: these operations are wrappers that make direct calls to the CoreAPI */
1966
/* INKProxyStateGet: get the proxy state (on/off)
1968
* Output: proxy state (on/off)
1970
inkapi INKProxyStateT
1973
return ProxyStateGet();
1976
/* INKProxyStateSet: set the proxy state (on/off)
1977
* Input: proxy_state - set to on/off
1978
* clear - start TS with cache clearing option,
1979
* when stopping TS should always be INK_CACHE_CLEAR_OFF
1983
INKProxyStateSet(INKProxyStateT proxy_state, INKCacheClearT clear)
1985
return ProxyStateSet(proxy_state, clear);
1988
/* INKReconfigure: tell traffic_server to re-read its configuration files
1995
return Reconfigure();
1998
/* INKRestart: restarts Traffic Server
1999
* Input: cluster - local or cluster-wide
2003
INKRestart(bool cluster)
2005
return Restart(cluster);
2008
/* INKHardRestart: a traffic_cop restart (restarts TM and TS),
2009
* essentially does a "start_traffic_server"/"stop_traffic_server" sequence
2012
* Note: only for remote API clients
2014
/* CAN ONLY BE IMPLEMENTED ON THE REMOTE SIDE !!! */
2018
return HardRestart(); // should return INK_ERR_FAIL
2021
/* INKActionDo: based on INKActionNeedT, will take appropriate action
2022
* Input: action - action that needs to be taken
2026
INKActionDo(INKActionNeedT action)
2031
case INK_ACTION_SHUTDOWN:
2032
ret = HardRestart();
2034
case INK_ACTION_RESTART:
2035
ret = Restart(true); // cluster wide by default?
2037
case INK_ACTION_RECONFIGURE:
2038
ret = Reconfigure();
2040
case INK_ACTION_DYNAMIC:
2041
/* do nothing - change takes effect immediately */
2042
return INK_ERR_OKAY;
2044
return INK_ERR_FAIL;
2051
/*--- diags output operations ---------------------------------------------*/
2053
INKDiags(INKDiagsT mode, const char *fmt, ...)
2055
// need to find way to pass arguments to the function
2058
va_start(ap, fmt); // initialize the argument pointer ap
2059
Diags(mode, fmt, ap);
2065
/* NOTE: user must deallocate the memory for the string returned */
2067
INKGetErrorMessage(INKError err_id)
2069
char msg[1024]; // need to define a MAX_ERR_MSG_SIZE???
2070
char *err_msg = NULL;
2074
snprintf(msg, sizeof(msg), "[%d] Everything's looking good.", err_id);
2076
case INK_ERR_READ_FILE: /* Error occur in reading file */
2077
snprintf(msg, sizeof(msg), "[%d] Unable to find/open file for reading.", err_id);
2079
case INK_ERR_WRITE_FILE: /* Error occur in writing file */
2080
snprintf(msg, sizeof(msg), "[%d] Unable to find/open file for writing.", err_id);
2082
case INK_ERR_PARSE_CONFIG_RULE: /* Error in parsing configuration file */
2083
snprintf(msg, sizeof(msg), "[%d] Error parsing configuration file.", err_id);
2085
case INK_ERR_INVALID_CONFIG_RULE: /* Invalid Configuration Rule */
2086
snprintf(msg, sizeof(msg), "[%d] Invalid configuration rule reached.", err_id);
2088
case INK_ERR_NET_ESTABLISH:
2089
snprintf(msg, sizeof(msg), "[%d] Error establishing socket conenction.", err_id);
2091
case INK_ERR_NET_READ: /* Error reading from socket */
2092
snprintf(msg, sizeof(msg), "[%d] Error reading from socket.", err_id);
2094
case INK_ERR_NET_WRITE: /* Error writing to socket */
2095
snprintf(msg, sizeof(msg), "[%d] Error writing to socket.", err_id);
2097
case INK_ERR_NET_EOF: /* Hit socket EOF */
2098
snprintf(msg, sizeof(msg), "[%d] Reached socket EOF.", err_id);
2100
case INK_ERR_NET_TIMEOUT: /* Timed out waiting for socket read */
2101
snprintf(msg, sizeof(msg), "[%d] Timed out waiting for socket read.", err_id);
2103
case INK_ERR_SYS_CALL: /* Error in sys/utility call, eg.malloc */
2104
snprintf(msg, sizeof(msg), "[%d] Error in basic system/utility call.", err_id);
2106
case INK_ERR_PARAMS: /* Invalid parameters for a fn */
2107
snprintf(msg, sizeof(msg), "[%d] Invalid parameters passed into function call.", err_id);
2110
snprintf(msg, sizeof(msg), "[%d] Generic Fail message (ie. CoreAPI call).", err_id);
2114
snprintf(msg, sizeof(msg), "[%d] Invalid error type.", err_id);
2118
err_msg = xstrdup(msg);
2123
/*--- password operations -------------------------------------------------*/
2125
INKEncryptPassword(char *passwd, char **e_passwd)
2128
INK_DIGEST_CTX md5_context;
2129
char passwd_md5[16];
2130
char *passwd_md5_str;
2131
int passwd_md5_str_len = 32;
2133
ink_debug_assert(passwd);
2134
ink_debug_assert(INK_ENCRYPT_PASSWD_LEN <= passwd_md5_str_len);
2136
const size_t md5StringSize = (passwd_md5_str_len + 1) * sizeof(char);
2137
passwd_md5_str = (char *) xmalloc(md5StringSize);
2138
if (!passwd_md5_str)
2139
return INK_ERR_FAIL;
2141
ink_code_incr_md5_init(&md5_context);
2142
ink_code_incr_md5_update(&md5_context, passwd, strlen(passwd));
2143
ink_code_incr_md5_final(passwd_md5, &md5_context);
2144
ink_code_md5_stringify(passwd_md5_str, md5StringSize, passwd_md5);
2146
// use only a subset of the MD5 string
2147
passwd_md5_str[INK_ENCRYPT_PASSWD_LEN] = '\0';
2148
*e_passwd = passwd_md5_str;
2150
return INK_ERR_OKAY;
2154
INKEncryptToFile(const char *passwd, const char *filepath)
2156
return EncryptToFile(passwd, filepath);
2159
/*--- direct file operations ----------------------------------------------*/
2161
INKConfigFileRead(INKFileNameT file, char **text, int *size, int *version)
2163
return ReadFile(file, text, size, version);
2167
INKConfigFileWrite(INKFileNameT file, char *text, int size, int version)
2169
return WriteFile(file, text, size, version);
2173
/* ReadFromUrl: reads a remotely located config file into a buffer
2174
* Input: url - remote location of the file
2175
* header - a buffer is allocated on the header char* pointer
2176
* headerSize - the size of the header buffer is returned
2177
* body - a buffer is allocated on the body char* pointer
2178
* bodySize - the size of the body buffer is returned
2179
* Output: INKError - INK_ERR_OKAY if succeed, INK_ERR_FAIL otherwise
2180
* Obsolete: inkapi INKError INKReadFromUrl (char *url, char **text, int *size);
2181
* NOTE: The URL can be expressed in the following forms:
2182
* - http://www.inktomi.com:80/products/network/index.html
2183
* - http://www.inktomi.com/products/network/index.html
2184
* - http://www.inktomi.com/products/network/
2185
* - http://www.inktomi.com/
2186
* - http://www.inktomi.com
2188
* NOTE: header and headerSize can be NULL
2191
INKReadFromUrl(char *url, char **header, int *headerSize, char **body, int *bodySize)
2193
//return ReadFromUrl(url, header, headerSize, body, bodySize);
2194
return INKReadFromUrlEx(url, header, headerSize, body, bodySize, URL_TIMEOUT);
2199
INKReadFromUrlEx(const char *url, char **header, int *headerSize, char **body, int *bodySize, int timeout)
2202
char *httpHost = NULL;
2203
char *httpPath = NULL;
2204
int httpPort = HTTP_PORT;
2205
int bufsize = URL_BUFSIZE;
2206
char buffer[URL_BUFSIZE];
2207
char request[BUFSIZE];
2210
INKError status = INK_ERR_OKAY;
2214
return INK_ERR_FAIL;
2216
timeout = URL_TIMEOUT;
2218
// Chop the protocol part, if it exists
2219
const char *doubleSlash = strstr(url, "//");
2221
url = doubleSlash + 2; // advance two positions to get rid of leading '//'
2223
// the path starts after the first occurrence of '/'
2224
const char *tempPath = strstr(url, "/");
2225
char *host_and_port;
2227
host_and_port = xstrndup(url, strlen(url) - strlen(tempPath));
2228
tempPath += 1; // advance one position to get rid of leading '/'
2229
httpPath = xstrdup(tempPath);
2231
host_and_port = xstrdup(url);
2232
httpPath = xstrdup("");
2235
// the port proceed by a ":", if it exists
2236
char *colon = strstr(host_and_port, ":");
2238
httpHost = xstrndup(host_and_port, strlen(host_and_port) - strlen(colon));
2239
colon += 1; // advance one position to get rid of leading ':'
2240
httpPort = ink_atoi(colon);
2242
httpPort = HTTP_PORT;
2244
httpHost = xstrdup(host_and_port);
2246
xfree(host_and_port);
2248
hFD = connectDirect(httpHost, httpPort, timeout);
2250
status = INK_ERR_NET_ESTABLISH;
2254
/* sending the HTTP request via the established socket */
2255
snprintf(request, BUFSIZE, "http://%s:%d/%s", httpHost, httpPort, httpPath);
2256
if ((status = sendHTTPRequest(hFD, request, (uint64_t) timeout)) != INK_ERR_OKAY)
2259
memset(buffer, 0, bufsize); /* empty the buffer */
2260
if ((status = readHTTPResponse(hFD, buffer, bufsize, (uint64_t) timeout)) != INK_ERR_OKAY)
2263
if ((status = parseHTTPResponse(buffer, &hdr_temp, headerSize, &bdy_temp, bodySize))
2267
if (header && headerSize)
2268
*header = xstrndup(hdr_temp, *headerSize);
2269
*body = xstrndup(bdy_temp, *bodySize);
2279
/*--- cache inspector operations -------------------------------------------*/
2282
INKLookupFromCacheUrl(INKString url, INKString * info)
2284
INKError err = INK_ERR_OKAY;
2286
char request[BUFSIZE];
2287
char response[URL_BUFSIZE];
2292
int timeout = URL_TIMEOUT;
2293
INKInt ts_port = 8080;
2295
if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
2298
if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
2302
snprintf(request, BUFSIZE, "http://{cache}/lookup_url?url=%s", url);
2303
if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
2306
memset(response, 0, URL_BUFSIZE);
2307
if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
2310
if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
2313
*info = xstrndup(body, bdy_size);
2320
INKLookupFromCacheUrlRegex(INKString url_regex, INKString * list)
2322
INKError err = INK_ERR_OKAY;
2324
char request[BUFSIZE];
2325
char response[URL_BUFSIZE];
2331
INKInt ts_port = 8080;
2333
if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
2336
if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
2340
snprintf(request, BUFSIZE, "http://{cache}/lookup_regex?url=%s", url_regex);
2341
if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
2344
memset(response, 0, URL_BUFSIZE);
2345
if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
2348
if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
2351
*list = xstrndup(body, bdy_size);
2357
INKDeleteFromCacheUrl(INKString url, INKString * info)
2359
INKError err = INK_ERR_OKAY;
2361
char request[BUFSIZE];
2362
char response[URL_BUFSIZE];
2367
int timeout = URL_TIMEOUT;
2368
INKInt ts_port = 8080;
2370
if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
2373
if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
2377
snprintf(request, BUFSIZE, "http://{cache}/delete_url?url=%s", url);
2378
if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
2381
memset(response, 0, URL_BUFSIZE);
2382
if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
2385
if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
2388
*info = xstrndup(body, bdy_size);
2395
INKDeleteFromCacheUrlRegex(INKString url_regex, INKString * list)
2397
INKError err = INK_ERR_OKAY;
2399
char request[BUFSIZE];
2400
char response[URL_BUFSIZE];
2406
INKInt ts_port = 8080;
2408
if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
2411
if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
2415
snprintf(request, BUFSIZE, "http://{cache}/delete_regex?url=%s", url_regex);
2416
if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
2419
memset(response, 0, URL_BUFSIZE);
2420
if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
2423
if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
2426
*list = xstrndup(body, bdy_size);
2432
INKInvalidateFromCacheUrlRegex(INKString url_regex, INKString * list)
2434
INKError err = INK_ERR_OKAY;
2436
char request[BUFSIZE];
2437
char response[URL_BUFSIZE];
2443
INKInt ts_port = 8080;
2445
if ((err = INKRecordGetInt("proxy.config.http.server_port", &ts_port)) != INK_ERR_OKAY)
2448
if ((fd = connectDirect("localhost", ts_port, timeout)) < 0) {
2452
snprintf(request, BUFSIZE, "http://{cache}/invalidate_regex?url=%s", url_regex);
2453
if ((err = sendHTTPRequest(fd, request, (uint64_t) timeout)) != INK_ERR_OKAY)
2456
memset(response, 0, URL_BUFSIZE);
2457
if ((err = readHTTPResponse(fd, response, URL_BUFSIZE, (uint64_t) timeout)) != INK_ERR_OKAY)
2460
if ((err = parseHTTPResponse(response, &header, &hdr_size, &body, &bdy_size)) != INK_ERR_OKAY)
2463
*list = xstrndup(body, bdy_size);
2468
/*--- snapshot operations -------------------------------------------------*/
2470
INKSnapshotTake(char *snapshot_name)
2472
return SnapshotTake(snapshot_name);
2476
INKSnapshotRestore(char *snapshot_name)
2478
return SnapshotRestore(snapshot_name);
2482
INKSnapshotRemove(char *snapshot_name)
2484
return SnapshotRemove(snapshot_name);
2488
INKSnapshotGetMlt(INKStringList snapshots)
2490
return SnapshotGetMlt((LLQ *) snapshots);
2493
/*--- events --------------------------------------------------------------*/
2495
INKEventSignal(char *event_name, ...)
2500
va_start(ap, event_name); // initialize the argument pointer ap
2501
ret = EventSignal(event_name, ap);
2507
INKEventResolve(char *event_name)
2509
return EventResolve(event_name);
2513
INKActiveEventGetMlt(INKList active_events)
2515
return ActiveEventGetMlt((LLQ *) active_events);
2519
INKEventIsActive(char *event_name, bool * is_current)
2521
return EventIsActive(event_name, is_current);
2525
INKEventSignalCbRegister(char *event_name, INKEventSignalFunc func, void *data)
2527
return EventSignalCbRegister(event_name, func, data);
2531
INKEventSignalCbUnregister(char *event_name, INKEventSignalFunc func)
2533
return EventSignalCbUnregister(event_name, func);
2536
/***************************************************************************
2537
* API Helper Functions for Data Carrier Structures
2538
***************************************************************************/
2540
/*--- abstracted file operations ------------------------------------------*/
2542
/* calls teh CfgContext class constructor */
2543
inkapi INKCfgContext
2544
INKCfgContextCreate(INKFileNameT file)
2546
return ((void *) CfgContextCreate(file));
2549
/* calls the CfgContext class destructor */
2551
INKCfgContextDestroy(INKCfgContext ctx)
2553
return (CfgContextDestroy((CfgContext *) ctx));
2557
INKCfgContextCommit(INKCfgContext ctx, INKActionNeedT * action_need, INKIntList errRules)
2559
NOWARN_UNUSED(action_need);
2560
return (CfgContextCommit((CfgContext *) ctx, (LLQ *) errRules));
2564
INKCfgContextGet(INKCfgContext ctx)
2566
return (CfgContextGet((CfgContext *) ctx));
2569
/*--- helper operations ---------------------------------------------------*/
2570
/* returns number of ele's in the INKCfgContext */
2572
INKCfgContextGetCount(INKCfgContext ctx)
2574
return CfgContextGetCount((CfgContext *) ctx);
2577
/* user must typecast the INKCfgEle to appropriate INKEle before using */
2579
INKCfgContextGetEleAt(INKCfgContext ctx, int index)
2581
return CfgContextGetEleAt((CfgContext *) ctx, index);
2586
INKCfgContextGetFirst(INKCfgContext ctx, INKCfgIterState * state)
2588
return CfgContextGetFirst((CfgContext *) ctx, state);
2592
INKCfgContextGetNext(INKCfgContext ctx, INKCfgIterState * state)
2594
return CfgContextGetNext((CfgContext *) ctx, state);
2598
INKCfgContextMoveEleUp(INKCfgContext ctx, int index)
2600
return CfgContextMoveEleUp((CfgContext *) ctx, index);
2604
INKCfgContextMoveEleDown(INKCfgContext ctx, int index)
2606
return CfgContextMoveEleDown((CfgContext *) ctx, index);
2611
INKCfgContextAppendEle(INKCfgContext ctx, INKCfgEle * ele)
2613
return CfgContextAppendEle((CfgContext *) ctx, ele);
2617
INKCfgContextInsertEleAt(INKCfgContext ctx, INKCfgEle * ele, int index)
2619
return CfgContextInsertEleAt((CfgContext *) ctx, ele, index);
2623
INKCfgContextRemoveEleAt(INKCfgContext ctx, int index)
2625
return CfgContextRemoveEleAt((CfgContext *) ctx, index);
2629
INKCfgContextRemoveAll(INKCfgContext ctx)
2631
return CfgContextRemoveAll((CfgContext *) ctx);
2634
/* checks if the fields in the ele are all valid */
2636
INKIsValid(INKCfgEle * ele)
2643
ele_obj = create_ele_obj_from_ele(ele);
2644
return (ele_obj->isValid());
2648
/*--- External FTP tcl script operations --------------------------------*/
2650
/* Process forking function for ftp.tcl helper */
2653
ftpProcessSpawn(const char *args[], char *output)
2662
size_t output_size = 4096;
2665
if (pipe(stdoutPipe) == -1)
2666
fprintf(stderr, "[ftpProcessSpawn] unable to create stdout pipe\n");
2669
if (pid == 0) { // child process
2670
dup2(stdoutPipe[1], STDOUT_FILENO);
2671
close(stdoutPipe[0]);
2673
pid = execv(args[0], (char* const*)&args[0]);
2675
fprintf(stderr, "[ftpProcessSpawn] unable to execv [%s,%s...]\n", args[0], args[1]);
2678
} else if (pid == -1) { // failed to create child process
2679
fprintf(stderr, "[ftpProcessSpawn] unable to fork [%d '%s']\n", errno, strerror(errno));
2681
} else { // parent process
2682
close(stdoutPipe[1]);
2683
/* read the output from child script process */
2684
while ((nbytes = read(stdoutPipe[0], buffer, 1024))) {
2685
if ((count + nbytes) < output_size) {
2686
strncpy(&output[count], buffer, nbytes);
2692
close(stdoutPipe[0]);
2694
waitpid(pid, &status, 0);
2696
fprintf(stderr, "[ftpProcessSpawn] script %s returns non-zero status '%d'", args[0], status);
2705
/* Process forking function for tcl_checker.sh helper */
2708
tclCheckProcessSpawn(char *args[], char *output)
2717
size_t output_size = 256;
2720
if (pipe(stdoutPipe) == -1)
2721
fprintf(stderr, "[tclCheckProcessSpawn] unable to create stdout pipe\n");
2724
if (pid == 0) { // child process
2725
dup2(stdoutPipe[1], STDOUT_FILENO);
2726
close(stdoutPipe[0]);
2728
pid = execv(args[0], &args[0]);
2730
fprintf(stderr, "[tclCheckProcessSpawn] unable to execv [%s,%s...]\n", args[0], args[1]);
2733
} else if (pid == -1) { // failed to create child process
2734
fprintf(stderr, "[tclCheckProcessSpawn] unable to fork [%d '%s']\n", errno, strerror(errno));
2736
} else { // parent process
2737
close(stdoutPipe[1]);
2738
/* read the output from child script process */
2739
while ((nbytes = read(stdoutPipe[0], buffer, 1024))) {
2740
if ((count + nbytes) < output_size) {
2741
strncpy(&output[count], buffer, nbytes);
2747
close(stdoutPipe[0]);
2749
waitpid(pid, &status, 0);
2751
fprintf(stderr, "[tclCheckProcessSpawn] script %s returns non-zero status '%d'", args[0], status);
2760
/* Snapshot Interface-centric function */
2763
INKMgmtFtp(const char *ftpCmd, const char *ftp_server_name, const char *ftp_login, const char *ftp_password, const char *local, const char *remote,
2766
char script_path[1024];
2767
char chk_script_path[1024];
2770
char *ui_path = NULL;
2771
INKRecordGetString("proxy.config.admin.html_doc_root", &ui_path);
2772
if (ui_path != NULL) {
2774
/* First we check to make sure we can use tcl on this plat */
2775
snprintf(chk_script_path, sizeof(chk_script_path), "%s/configure/helper/INKMgmtAPICheckTcl.sh", ui_path);
2776
char *chk_args[] = {
2780
/* tclCheckProcessSpawn.sh sends nothing back on stdout if check OK... */
2781
chk_status = tclCheckProcessSpawn(chk_args, output);
2782
if (chk_status == 0) {
2783
/* Go ahead and try the using the FTP .tcl script */
2784
snprintf(script_path, sizeof(script_path), "%s/configure/helper/INKMgmtAPIFtp.tcl", ui_path);
2785
const char *args[] = {
2795
status = ftpProcessSpawn(args, output);
2801
return INK_ERR_FAIL;
2802
return INK_ERR_OKAY;
2805
/* Network conifguration functions */
2807
// close all file descriptors belong to process specified by pid
2811
const int BUFFLEN = 200;
2812
char command[BUFFLEN];
2813
char buffer[BUFFLEN]; // this is assumption.. so would break if some one try to hack this.
2816
// WARNING: this part of code doesn't work yet. for some strange reason, we can not upgrade
2818
if (getuid() != 0) { // if not super user, need to upgrade to root
2819
//printf("before upgrade:current uid%d, euid %d\n", getuid(), geteuid()); fflush(stdout);
2822
//printf("after upgrade:current uid %d, euid %d\n", getuid(), geteuid()); fflush(stdout);
2825
if (getuid() == 0 || geteuid() == 0) { // only if it's successful
2826
snprintf(command, sizeof(command), "/bin/ls -1 /proc/%" PRId64 "/fd", (int64_t)getpid());
2827
FILE *fd = popen(command, "r");
2830
NOWARN_UNUSED_RETURN(fgets(buffer, BUFFLEN, fd));
2832
if (num != fileno(fd) && num != 0 && num != 1 && num != 2) { // for out put
2833
//printf("closing fd (%d)\n", num); fflush(stdout);
2842
inkapi INKError rm_start_proxy()
2846
static time_t rm_last_stop = 0;
2848
time_t time_diff = time(NULL) - rm_last_stop;
2850
if (time_diff > 60 || time_diff < 0) { // wrap around?? shall never happen
2852
const char *argv[3];
2853
argv[0] = "net_config";
2856
char command_path[PATH_NAME_MAX + 1];
2857
Layout::relative_to(command_path, sizeof(command_path),
2858
Layout::get()->bindir, "net_config");
2860
rm_last_stop = time(NULL);
2862
if ((pid = fork()) < 0) {
2864
} else if (pid > 0) {
2868
close(1); // close STDOUT
2869
close(2); // close STDERR
2871
int res = execv(command_path, (char* const*)argv);
2873
perror("[rm_start_proxy] net_config stop_proxy failed! ");
2877
} // else already try to stop within 60s Window, skip
2879
return INK_ERR_OKAY;
2883
/*****************************************************************
2884
* Traffic server changes necessary when network config is changed
2885
*****************************************************************/
2888
INKSetHostname(INKString hostname)
2890
INKActionNeedT action_need = INK_ACTION_UNDEFINED, top_action_req = INK_ACTION_UNDEFINED;
2893
/* Here we should handle these cases:
2894
* rmserver.cfg - different API currently, records.config, mrtg, and hostname_FQ
2897
if (INKRecordGetInt("proxy.local.cluster.type", &val) == INK_ERR_OKAY) { //If error??
2899
if (MgmtRecordSet("proxy.config.proxy_name", hostname, &action_need) != INK_ERR_OKAY)
2900
return INK_ERR_FAIL;
2904
if (action_need < top_action_req) // a more severe action
2905
top_action_req = action_need;
2907
//FIXME - currently MRTG is all about hard coded hostname - this is where we should fix it
2908
//Currently it is fixed in net_config
2910
//if (!(mrtg_update_hostname(hostname)))
2911
// return INK_ERR_WRITE_FILE;
2913
//Also, we use this variable sometimes - needs to be fixed
2915
if (MgmtRecordSet("proxy.node.hostname_FQ", hostname, &action_need) != INK_ERR_OKAY)
2916
return INK_ERR_FAIL;
2918
//carry out the appropriate action
2919
if (action_need < top_action_req) // a more severe action
2920
top_action_req = action_need;
2922
if (top_action_req != INK_ACTION_UNDEFINED) {
2923
//return INKActionDo(top_action_req); //right now we mark this out as this is not needed and causes hangs - verify this FIX - bz49778
2924
return INK_ERR_OKAY;
2926
return INK_ERR_OKAY;
2931
INKSetGateway(INKString gateway_ip)
2933
NOWARN_UNUSED(gateway_ip);
2934
//Nothing to be done for now
2935
return INK_ERR_OKAY;
2940
INKSetDNSServers(INKString dns_ips)
2942
NOWARN_UNUSED(dns_ips);
2943
//Nothing to be done for now
2944
return INK_ERR_OKAY;
2949
INKSetNICUp(INKString nic_name, bool static_ip, INKString ip, INKString old_ip, INKString netmask, bool onboot,
2950
INKString gateway_ip)
2952
NOWARN_UNUSED(nic_name);
2953
NOWARN_UNUSED(static_ip);
2955
NOWARN_UNUSED(old_ip);
2956
NOWARN_UNUSED(netmask);
2957
NOWARN_UNUSED(onboot);
2958
NOWARN_UNUSED(gateway_ip);
2959
/* there is no ipnat conf file anymore,
2960
commenting out the rest of this function */
2961
return INK_ERR_READ_FILE;
2965
INKIpFilterEle *ele, *ele_copy;
2966
INKActionNeedT action_need=INK_ACTION_UNDEFINED;
2969
//ctx = INKCfgContextCreate(INK_FNAME_IPNAT);
2972
//Debug("config", "[INKSetNICUp] can't allocate ctx memory");
2973
return INK_ERR_FAIL;
2976
if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
2977
//if (ctx) INKCfgContextDestroy(ctx);
2978
return INK_ERR_READ_FILE;
2981
if ((i = INKCfgContextGetCount(ctx)) <=0 ) {
2982
//if (ctx) INKCfgContextDestroy(ctx);
2983
return INK_ERR_FAIL;
2986
if (strcmp(nic_name, "eth0") == 0) { //currently we hard code it - should be changed
2987
for (index=0 ; index<i ; index++) {
2988
ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
2990
if (strcmp(ele->intr,nic_name) == 0) {
2991
//if (strcmp(ele->dest_ip_addr, old_ip) == 0) //INKqa12486
2992
ele->dest_ip_addr = string_to_ip_addr(ip);
2996
} else { //it is not eth0
2999
for (index=0 ; index<i ; index++) {
3000
ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
3002
if (strcmp(ele->intr,nic_name) == 0) {
3004
//if (strcmp(ele->dest_ip_addr, old_ip) == 0) //INKqa12486
3005
ele->dest_ip_addr = string_to_ip_addr(ip);
3009
if (!found) { //create the rules for the new NIC according to eth0
3010
for (index=0 ; index<i ; index++) {
3011
ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
3013
if (strcmp(ele->intr, "eth0") == 0) {
3014
ele_copy = INKIpFilterEleCreate();
3016
ele_copy->intr = xstrdup(nic_name); // ethernet interface
3017
ele_copy->src_ip_addr = ele->src_ip_addr; // from IP
3018
ele_copy->src_cidr = ele->src_cidr;
3019
ele_copy->src_port = ele->src_port; // from port
3020
ele_copy->dest_ip_addr = string_to_ip_addr(ip); // to IP
3021
ele_copy->dest_port = ele->dest_port; // to port
3022
ele_copy->type_con = ele->type_con;
3023
ele_copy->protocol = ele->protocol;
3025
INKCfgContextAppendEle(ctx, (INKCfgEle*)ele_copy); // add new ele to end of list
3032
// commit the CfgContext to write a new version of the file
3033
if (INKCfgContextCommit(ctx, &action_need, NULL) != INK_ERR_OKAY) {
3034
//if (ctx) INKCfgContextDestroy(ctx);
3035
return INK_ERR_FAIL;
3037
//if (ctx) INKCfgContextDestroy(ctx);
3040
if ( action_need != INK_ACTION_UNDEFINED ){
3041
return INKActionDo(action_need);
3044
return INK_ERR_OKAY;
3050
INKSetProxyPort(INKString proxy_port)
3052
NOWARN_UNUSED(proxy_port);
3053
/* there is no ipnat.conf file anymore,
3054
commenting out the rest of this function */
3055
return INK_ERR_READ_FILE;
3059
INKIpFilterEle *ele;
3060
INKActionNeedT action_need=INK_ACTION_UNDEFINED;
3063
//ctx = INKCfgContextCreate(INK_FNAME_IPNAT);
3065
//Debug("config", "[INKSetNICUp] can't allocate ctx memory");
3066
return INK_ERR_FAIL;
3069
if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
3070
//if (ctx) INKCfgContextDestroy(ctx);
3071
return INK_ERR_READ_FILE;
3074
if ((i = INKCfgContextGetCount(ctx)) <=0 ) {
3075
//if (ctx) INKCfgContextDestroy(ctx);
3076
return INK_ERR_FAIL;
3079
for (index=0 ; index<i ; index++) {
3080
ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
3082
if (ele->src_port == 80) {
3083
ele->dest_port = ink_atoi(proxy_port);
3084
// Debug("api2","[INKSetProxyPort] %d is the dest_port for port %d now.\n",ele->dest_port, ele->src_port);
3089
// commit the CfgContext to write a new version of the file
3090
if (INKCfgContextCommit(ctx, &action_need, NULL) != INK_ERR_OKAY) {
3091
//if (ctx) INKCfgContextDestroy(ctx);
3092
return INK_ERR_FAIL;
3094
//if (ctx) INKCfgContextDestroy(ctx);
3096
if ( action_need != INK_ACTION_UNDEFINED ){
3097
return INKActionDo(action_need);
3100
return INK_ERR_OKAY;
3106
INKSetNICDown(INKString nic_name, INKString ip_addrr)
3108
NOWARN_UNUSED(nic_name);
3109
NOWARN_UNUSED(ip_addrr);
3110
/* there is no ipnat.conf file anymore,
3111
commenting out the rest of this function */
3112
return INK_ERR_READ_FILE;
3116
INKIpFilterEle *ele;
3117
INKActionNeedT action_need = INK_ACTION_UNDEFINED;
3119
// This isn't used any more, code commented out below. /leif
3120
//INKCfgIterState ctx_state;
3123
//ctx = INKCfgContextCreate(INK_FNAME_IPNAT);
3126
//Debug("config", "[INKSetNicDown] can't allocate ctx memory");
3127
return INK_ERR_FAIL;
3130
if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
3131
//if (ctx) INKCfgContextDestroy(ctx);
3132
return INK_ERR_READ_FILE;
3135
ele = (INKIpFilterEle *)INKCfgContextGetFirst(ctx, &ctx_state);
3138
if (strcmp(ele->intr, nic_name) == 0) INKCfgContextRemoveEleAt (ctx, index);
3139
ele = (INKIpFilterEle *)INKCfgContextGetNext(ctx, &ctx_state);
3145
for (index=0 ; index< INKCfgContextGetCount(ctx); index++) {
3146
ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
3148
if (strcmp(ele->intr, nic_name) == 0) {
3149
INKCfgContextRemoveEleAt (ctx, index);
3156
// commit the CfgContext to write a new version of the file
3157
if (INKCfgContextCommit(ctx, &action_need, NULL) != INK_ERR_OKAY) {
3158
//if (ctx) INKCfgContextDestroy(ctx);
3159
return INK_ERR_FAIL;
3161
//if (ctx) INKCfgContextDestroy(ctx);
3163
if ( action_need != INK_ACTION_UNDEFINED) {
3164
return INKActionDo(action_need);
3167
return INK_ERR_OKAY;
3174
INKSetSearchDomain(const char *search_name)
3176
NOWARN_UNUSED(search_name);
3177
//Nothing to be done for now
3178
return INK_ERR_OKAY;
3181
/* The following 2 functions set the Realm field in rmserver.cfg file. */
3183
resetHostName(INKRmServerEle * ele, const char *hostname, const char *tail)
3185
char buff[MAX_RULE_SIZE];
3186
xfree(ele->str_val);
3187
snprintf(buff, sizeof(buff), "%s.%s", hostname, tail);
3188
ele->str_val = xstrdup(buff);
3193
INKSetRmRealm(const char *hostname)
3197
INKRmServerEle *ele;
3198
Tokenizer tokens("\n");
3199
INKActionNeedT action_need;
3201
INKError err = INK_ERR_OKAY;
3204
ctx = INKCfgContextCreate(INK_FNAME_RMSERVER);
3206
// Debug("config", "[net_config:Config] can't allocate ctx memory");
3209
if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
3210
// Debug("config", "[net_config:Config] Failed to Get CfgContext");
3213
ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_SCU_ADMIN_REALM);
3214
resetHostName(ele, hostname, "AdminRealm");
3215
ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_CNN_REALM);
3216
resetHostName(ele, hostname, "ConnectRealm");
3217
ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_ADMIN_FILE_REALM);
3218
resetHostName(ele, hostname, "AdminRealm");
3219
ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_AUTH_REALM);
3220
resetHostName(ele, hostname, "ConnectRealm");
3221
response = INKCfgContextCommit(ctx, &action_need, NULL);
3222
if (response == INK_ERR_INVALID_CONFIG_RULE) {
3223
// MgmtAPI should return INK_ not WEB_
3224
// err = WEB_HTTP_ERR_INVALID_CFG_RULE;
3225
err = INK_ERR_INVALID_CONFIG_RULE;
3226
} else if (response != INK_ERR_OKAY) {
3229
INKCfgContextDestroy(ctx);
3234
INKCfgContextDestroy(ctx);
3238
/* this function change the PNA_REDIREDT IP address of rmserver.cfg file. */
3240
INKSetRmPNA_RDT_IP(const char *ip)
3243
INKRmServerEle *ele;
3244
Tokenizer tokens("\n");
3245
INKActionNeedT action_need;
3247
INKError err = INK_ERR_OKAY;
3248
char buff[MAX_RULE_SIZE];
3250
ctx = INKCfgContextCreate(INK_FNAME_RMSERVER);
3252
// Debug("config", "[net_config:Config] can't allocate ctx memory");
3255
if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
3256
// Debug("config", "[net_config:Config] Failed to Get CfgContext");
3259
ele = (INKRmServerEle *) CfgContextGetEleAt((CfgContext *) ctx, (int) INK_RM_RULE_PNA_RDT_IP);
3261
xfree(ele->str_val);
3262
snprintf(buff, sizeof(buff), "%s", ip);
3263
ele->str_val = xstrdup(buff);
3265
response = INKCfgContextCommit(ctx, &action_need, NULL);
3266
if (response == INK_ERR_INVALID_CONFIG_RULE) {
3267
// MgmtAPI should return INK_ not WEB_
3268
// err = WEB_HTTP_ERR_INVALID_CFG_RULE;
3269
err = INK_ERR_INVALID_CONFIG_RULE;
3270
} else if (response != INK_ERR_OKAY) {
3273
//INKCfgContextDestroy(ctx);
3278
INKCfgContextDestroy(ctx);
3282
/* this function change the PNA_REDIRET port in ipnat.conf file. */
3284
INKSetPNA_RDT_Port(const int port)
3286
NOWARN_UNUSED(port);
3287
/* there is no ipnat conf file anymore,
3288
commenting out the rest of this function */
3289
return INK_ERR_READ_FILE;
3293
INKIpFilterEle *ele;
3294
INKActionNeedT action_need=INK_ACTION_UNDEFINED;
3298
//ctx = INKCfgContextCreate(INK_FNAME_IPNAT);
3301
return INK_ERR_FAIL;
3304
if (INKCfgContextGet(ctx) != INK_ERR_OKAY) {
3305
return INK_ERR_READ_FILE;
3307
if ((i = INKCfgContextGetCount(ctx)) <=0 ) {
3308
return INK_ERR_FAIL;
3311
for (index=0 ; index<i ; index++) {
3312
ele = (INKIpFilterEle *)INKCfgContextGetEleAt(ctx, index);
3314
if (ele->src_port == 7070) {
3315
ele->dest_port = port;
3321
// commit the CfgContext to write a new version of the file
3322
if (INKCfgContextCommit(ctx, &action_need, NULL) != INK_ERR_OKAY) {
3323
return INK_ERR_FAIL;
3326
if ( action_need != INK_ACTION_UNDEFINED) {
3327
return INKActionDo(action_need);
3330
return INK_ERR_OKAY;