~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/Main.cc

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-05-09 01:00:04 UTC
  • mto: (1.1.11) (5.3.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20130509010004-9fqq9n0adseg3f8w
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
#include "RemapProcessor.h"
87
87
#include "XmlUtils.h"
88
88
#include "I_Tasks.h"
 
89
#include "InkAPIInternal.h"
89
90
 
90
91
#include <ts/ink_cap.h>
91
92
 
96
97
//
97
98
// Global Data
98
99
//
99
 
#define DEFAULT_NUMBER_OF_THREADS         ink_number_of_processors()
100
 
#define DEFAULT_NUMBER_OF_UDP_THREADS     1
101
 
#define DEFAULT_NUMBER_OF_SSL_THREADS     0
102
 
#define DEFAULT_NUM_ACCEPT_THREADS        0
103
 
#define DEFAULT_NUM_TASK_THREADS          0
104
100
#define DEFAULT_HTTP_ACCEPT_PORT_NUMBER   0
105
101
#define DEFAULT_COMMAND_FLAG              0
106
102
#define DEFAULT_LOCK_PROCESS              0
118
114
#define DEFAULT_REMOTE_MANAGEMENT_FLAG    0
119
115
 
120
116
static void * mgmt_restart_shutdown_callback(void *, char *, int data_len);
121
 
static bool xmlBandwidthSchemaRead(XMLNode * node);
122
117
 
123
118
static int version_flag = DEFAULT_VERSION_FLAG;
124
119
 
125
120
static int const number_of_processors = ink_number_of_processors();
126
 
static int num_of_net_threads = DEFAULT_NUMBER_OF_THREADS;
 
121
static int num_of_net_threads = number_of_processors;
 
122
static int num_of_udp_threads = 0;
 
123
static int num_accept_threads  = 0;
 
124
static int num_task_threads = 0;
 
125
 
127
126
extern int num_of_cluster_threads;
128
 
static int num_of_udp_threads = DEFAULT_NUMBER_OF_UDP_THREADS;
129
 
static int num_accept_threads  = DEFAULT_NUM_ACCEPT_THREADS;
130
 
static int num_task_threads = DEFAULT_NUM_TASK_THREADS;
 
127
 
131
128
#if TS_HAS_TESTS
132
129
static int run_test_hook = 0;
133
130
#endif
405
402
    ink_strlcpy(management_directory, Layout::get()->sysconfdir, sizeof(management_directory));
406
403
    if (access(management_directory, R_OK) == -1) {
407
404
      fprintf(stderr,"unable to access() management path '%s': %d, %s\n", management_directory, errno, strerror(errno));
408
 
      fprintf(stderr,"please set management path via command line '-d <managment directory>'\n");
 
405
      fprintf(stderr,"please set management path via command line '-d <management directory>'\n");
409
406
      _exit(1);
410
407
    }
411
408
  }
1278
1275
 
1279
1276
  char *buf = (char *)ats_malloc(buflen);
1280
1277
 
1281
 
  if (0 != geteuid() && 0 == getuid()) seteuid(0); // revert euid if possible.
 
1278
  if (0 != geteuid() && 0 == getuid())
 
1279
    NOWARN_UNUSED_RETURN(seteuid(0)); // revert euid if possible.
1282
1280
  if (0 != geteuid()) {
1283
1281
    // Not root so can't change user ID. Logging isn't operational yet so
1284
1282
    // we have to write directly to stderr. Perhaps this should be fatal?
1520
1518
  TS_ReadConfigInteger(history_info_enabled, "proxy.config.history_info_enabled");
1521
1519
  TS_ReadConfigInteger(res_track_memory, "proxy.config.res_track_memory");
1522
1520
 
1523
 
  {
1524
 
    XMLDom schema;
1525
 
    //char *configPath = TS_ConfigReadString("proxy.config.config_dir");
1526
 
    char *filename = TS_ConfigReadString("proxy.config.bandwidth_mgmt.filename");
1527
 
    char bwFilename[PATH_NAME_MAX];
1528
 
 
1529
 
    snprintf(bwFilename, sizeof(bwFilename), "%s/%s", system_config_directory, filename);
1530
 
    ats_free(filename);
1531
 
 
1532
 
    Debug("bw-mgmt", "Looking to read: %s for bw-mgmt", bwFilename);
1533
 
    schema.LoadFile(bwFilename);
1534
 
    xmlBandwidthSchemaRead(&schema);
1535
 
  }
1536
 
 
1537
 
 
1538
1521
  init_http_header();
1539
1522
 
1540
1523
  // Sanity checks
1541
 
  //  if (!lock_process) check_for_root_uid();
1542
1524
  check_fd_limit();
1543
 
 
1544
1525
  command_flag = command_flag || *command_string;
1545
1526
 
1546
1527
  // Set up store
1627
1608
    initCacheControl();
1628
1609
#endif
1629
1610
    initCongestionControl();
1630
 
    IpAllow::InitInstance();
 
1611
    IpAllow::startup();
1631
1612
    ParentConfig::startup();
1632
1613
#ifdef SPLIT_DNS
1633
1614
    SplitDNSConfig::startup();
1655
1636
    HttpProxyPort::loadDefaultIfEmpty();
1656
1637
 
1657
1638
    cacheProcessor.start();
1658
 
    udpNet.start(num_of_udp_threads);
 
1639
 
 
1640
    // UDP net-threads are turned off by default.
 
1641
    if (!num_of_udp_threads)
 
1642
      TS_ReadConfigInteger(num_of_udp_threads, "proxy.config.udp.threads");
 
1643
    if (num_of_udp_threads)
 
1644
      udpNet.start(num_of_udp_threads);
 
1645
 
1659
1646
    sslNetProcessor.start(getNumSSLThreads());
1660
1647
 
1661
1648
#ifndef INK_NO_LOG
1663
1650
    Log::init(remote_management_flag ? 0 : Log::NO_REMOTE_MANAGEMENT);
1664
1651
#endif
1665
1652
 
1666
 
#if !defined(TS_NO_API)
1667
 
    plugin_init(system_config_directory, true); // extensions.config
1668
 
#endif
1669
 
 
1670
1653
    //acc.init();
1671
1654
    //if (auto_clear_authdb_flag)
1672
1655
     // acc.clear_cache();
1730
1713
    }
1731
1714
 
1732
1715
#ifndef TS_NO_API
1733
 
    plugin_init(system_config_directory, false);        // plugin.config
 
1716
    plugin_init(system_config_directory);        // plugin.config
1734
1717
#else
1735
1718
    api_init();                 // we still need to initialize some of the data structure other module needs.
1736
1719
    // i.e. http_global_hooks
 
1720
    pmgmt->registerPluginCallbacks(global_config_cbs);
1737
1721
#endif
1738
1722
 
1739
1723
    // "Task" processor, possibly with its own set of task threads
1786
1770
}
1787
1771
 
1788
1772
 
1789
 
static bool
1790
 
xmlBandwidthSchemaRead(XMLNode * node)
1791
 
{
1792
 
  XMLNode *child, *c2;
1793
 
  int i, j, k;
1794
 
  unsigned char *p;
1795
 
  char *ip;
1796
 
 
1797
 
  // file doesn't exist
1798
 
  if (node->getNodeName() == NULL) {
1799
 
    // alloc 1-elt array to store stuff for best-effort traffic
1800
 
    G_inkPipeInfo.perPipeInfo = NEW(new InkSinglePipeInfo[1]);
1801
 
    G_inkPipeInfo.perPipeInfo[0].wt = 1.0;
1802
 
    G_inkPipeInfo.numPipes = 0;
1803
 
    G_inkPipeInfo.interfaceMbps = 0.0;
1804
 
    return true;
1805
 
  }
1806
 
 
1807
 
  if (strcmp(node->getNodeName(), "interface") != 0) {
1808
 
    Debug("bw-mgmt", "Root node should be an interface tag!\n");
1809
 
    return false;
1810
 
  }
1811
 
  // First entry G_inkPipeInfo.perPipeInfo[0] is the one for "best-effort" traffic.
1812
 
  G_inkPipeInfo.perPipeInfo = NEW(new InkSinglePipeInfo[node->getChildCount() + 1]);
1813
 
  G_inkPipeInfo.perPipeInfo[0].wt = 1.0;
1814
 
  G_inkPipeInfo.numPipes = 0;
1815
 
  G_inkPipeInfo.reliabilityMbps = 1.0;
1816
 
  G_inkPipeInfo.interfaceMbps = 30.0;
1817
 
  for (i = 0; i < node->getChildCount(); i++) {
1818
 
    if ((child = node->getChildNode(i))) {
1819
 
      if (strcmp(child->getNodeName(), "pipe") == 0) {
1820
 
        G_inkPipeInfo.numPipes++;
1821
 
        for (k = 0; k < child->getChildCount(); k++) {
1822
 
          c2 = child->getChildNode(k);
1823
 
          for (int l = 0; l < c2->m_nACount; l++) {
1824
 
            if (strcmp(c2->m_pAList[l].pAName, "weight") == 0) {
1825
 
              G_inkPipeInfo.perPipeInfo[G_inkPipeInfo.numPipes].wt = atof(c2->m_pAList[l].pAValue);
1826
 
              G_inkPipeInfo.perPipeInfo[0].wt -= G_inkPipeInfo.perPipeInfo[G_inkPipeInfo.numPipes].wt;
1827
 
            } else if (strcmp(c2->m_pAList[l].pAName, "dest_ip") == 0) {
1828
 
              p = (unsigned char *) &(G_inkPipeInfo.perPipeInfo[G_inkPipeInfo.numPipes].destIP);
1829
 
              ip = c2->m_pAList[l].pAValue;
1830
 
              for (j = 0; j < 4; j++) {
1831
 
                p[j] = atoi(ip);
1832
 
                while (ip && *ip && (*ip != '.'))
1833
 
                  ip++;
1834
 
                ip++;
1835
 
              }
1836
 
            }
1837
 
          }
1838
 
        }
1839
 
      } else if (strcmp(child->getNodeName(), "bandwidth") == 0) {
1840
 
        for (j = 0; j < child->m_nACount; j++) {
1841
 
          if (strcmp(child->m_pAList[j].pAName, "limit_mbps") == 0) {
1842
 
            G_inkPipeInfo.interfaceMbps = atof(child->m_pAList[j].pAValue);
1843
 
          } else if (strcmp(child->m_pAList[j].pAName, "reliability_mbps") == 0) {
1844
 
            G_inkPipeInfo.reliabilityMbps = atof(child->m_pAList[j].pAValue);
1845
 
          }
1846
 
        }
1847
 
      }
1848
 
    }
1849
 
  }
1850
 
  Debug("bw-mgmt", "Read in: limit_mbps = %lf\n", G_inkPipeInfo.interfaceMbps);
1851
 
  for (i = 0; i < G_inkPipeInfo.numPipes + 1; i++) {
1852
 
    G_inkPipeInfo.perPipeInfo[i].bwLimit =
1853
 
      (int64_t) (G_inkPipeInfo.perPipeInfo[i].wt * G_inkPipeInfo.interfaceMbps * 1024.0 * 1024.0);
1854
 
    p = (unsigned char *) &(G_inkPipeInfo.perPipeInfo[i].destIP);
1855
 
    Debug("bw-mgmt", "Pipe [%d]: wt = %lf, dest ip = %d.%d.%d.%d\n",
1856
 
          i, G_inkPipeInfo.perPipeInfo[i].wt, p[0], p[1], p[2], p[3]);
1857
 
  }
1858
 
  return true;
1859
 
}
1860
 
 
1861
 
 
1862
1773
#if TS_HAS_TESTS
1863
1774
//////////////////////////////
1864
1775
// Unit Regresion Test Hook //