NS PolicyConfig Guide
NS PolicyConfig Guide
NS PolicyConfig Guide
Citrix NetScaler 10
CITRIX SYSTEMS, INC., 2012. ALL RIGHTS RESERVED. NO PART OF THIS DOCUMENT MAY BE REPRODUCED OR TRANSMITTED IN ANY FORM OR BY ANY MEANS OR USED TO MAKE DERIVATIVE WORK (SUCH AS TRANSLATION, TRANSFORMATION, OR ADAPTATION) WITHOUT THE EXPRESS WRITTEN PERMISSION OF CITRIX SYSTEMS, INC. ALTHOUGH THE MATERIAL PRESENTED IN THIS DOCUMENT IS BELIEVED TO BE ACCURATE, IT IS PRESENTED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. USERS MUST TAKE ALL RESPONSIBILITY FOR THE USE OR APPLICATION OF THE PRODUCT(S) DESCRIBED IN THIS MANUAL. CITRIX SYSTEMS, INC. OR ITS SUPPLIERS DO NOT ASSUME ANY LIABILITY THAT MAY OCCUR DUE TO THE USE OR APPLICATION OF THE PRODUCT(S) DESCRIBED IN THIS DOCUMENT. INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE WITHOUT NOTICE. COMPANIES, NAMES, AND DATA USED IN EXAMPLES ARE FICTITIOUS UNLESS OTHERWISE NOTED. The following information is for FCC compliance of Class A devices: This equipment has been tested and found to comply with the limits for a Class A digital device, pursuant to part 15 of the FCC rules. These limits are designed to provide reasonable protection against harmful interference when the equipment is operated in a commercial environment. This equipment generates, uses, and can radiate radio-frequency energy and, if not installed and used in accordance with the instruction manual, may cause harmful interference to radio communications. Operation of this equipment in a residential area is likely to cause harmful interference, in which case users will be required to correct the interference at their own expense. Modifying the equipment without Citrix' written authorization may result in the equipment no longer complying with FCC requirements for Class A digital devices. In that event, your right to use the equipment may be limited by FCC regulations, and you may be required to correct any interference to radio or television communications at your own expense. You can determine whether your equipment is causing interference by turning it off. If the interference stops, it was probably caused by the NetScaler appliance. If the NetScaler equipment causes interference, try to correct the interference by using one or more of the following measures: Move the NetScaler equipment to one side or the other of your equipment. Move the NetScaler equipment farther away from your equipment. Plug the NetScaler equipment into an outlet on a different circuit from your equipment. (Make sure the NetScaler equipment and your equipment are on circuits controlled by different circuit breakers or fuses.) Modifications to this product not authorized by Citrix Systems, Inc., could void the FCC approval and negate your authority to operate the product. BroadCom is a registered trademark of BroadCom Corporation. Fast Ramp, NetScaler, and NetScaler Request Switch are trademarks of Citrix Systems, Inc. Linux is a registered trademark of Linus Torvalds. Internet Explorer, Microsoft, PowerPoint, Windows and Windows product names such as Windows NT are trademarks or registered trademarks of the Microsoft Corporation. NetScape is a registered trademark of Netscape Communications Corporation. Red Hat is a trademark of Red Hat, Inc. Sun and Sun Microsystems are registered trademarks of Sun Microsystems, Inc. Other brand and product names may be registered trademarks or trademarks of their respective holders. Portions of this software may be redistributed under an open source license. Information about those portions of the software, including a listing of all third party attribution notices and open source license agreements can be found at http:// www.citrix.com/lang/English/lp/lp_2305124.asp. All rights reserved. Last Updated: March 2012 Document code: May 17 2012 06:29:23
Contents
Preface..................................................................................................15
Formatting Conventions for NetScaler Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15 Documentation Available on the NetScaler Appliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16 Getting Service and Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 NetScaler Documentation Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
iii
Contents
Parameters for converting the classic expressions in a NetScaler configuration file to the default syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34 Conversion Warnings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34 About Migration from Classic to Default Syntax Policies and Expressions. . . . . . . . . . . . . . . . .35 Before You Proceed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
iv
To display policy bindings by using the NetScaler command line. . . . . . . . . . . . . . . .53 To display global policy bindings for Integrated Caching, Rewrite, or Responder by using the configuration utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 To display global policy bindings for DNS or Clientless Access in the Access Gateway by using the configuration utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54 To display global policy bindings for Content Switching by using the configuration utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Unbinding a Policy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54 To unbind an integrated caching, rewrite, or compression default syntax policy globally by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54 To unbind a responder policy globally by using the NetScaler command line. . . . . . . . 55 To unbind a DNS policy globally by using the NetScaler command line. . . . . . . . . . . . . . 55 To unbind a default syntax policy from a virtual server by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 To unbind an integrated caching, responder, rewrite, or compression default syntax policy globally by using the configuration utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 To unbind a DNS policy globally by using the configuration utility. . . . . . . . . . . . . . . . . . . . .57 To unbind a default syntax policy from a load balancing or content switching virtual server by using the configuration utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57 Creating Policy Labels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Creating Policy Labels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 To create a caching policy label by using the NetScaler command line. . . . . . . . . 58 To create a Content Switching policy label by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58 To create a Rewrite policy label by using the NetScaler command line. . . . . . . . . .59 To create a Responder policy label by using the NetScaler command line. . . . . .59 To create a policy label by using the configuration utility. . . . . . . . . . . . . . . . . . . . . . . . . 60 Binding a Policy to a Policy Label. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Configuring a Policy Label or Virtual Server Policy Bank. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Configuring a Policy Label. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 To configure a policy label by using the NetScaler command line. . . . . . . . . . . . . . . 62 To invoke a policy label from a Rewrite policy bank with a NOPOLICY entry by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62 To invoke a policy label from an Integrated Caching policy bank by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63 To invoke a policy label from a Responder policy bank by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 To configure a policy label by using the configuration utility. . . . . . . . . . . . . . . . . . . . . .64 Configuring a Policy Bank for a Virtual Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 v
Contents
To add policies to a virtual server policy bank by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 To invoke a policy label from a virtual server policy bank with a NOPOLICY entry by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65 To configure a virtual server policy bank by using the configuration utility. . . . . . .66 Invoking or Removing a Policy Label or Virtual Server Policy Bank. . . . . . . . . . . . . . . . . . . . . . . .67 To invoke a rewrite or integrated caching policy label by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67 To invoke a responder policy label by using the NetScaler command line. . . . . . . . . . . .68 To invoke a Virtual Server Policy Bank by using the NetScaler command line. . . . . . .68 To remove a rewrite or integrated caching policy label by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69 To remove a responder policy label by using the NetScaler command line. . . . . . . . . . .69 To remove a Virtual Server policy label by using the NetScaler command line. . . . . . .70 To invoke a policy label or virtual server policy bank by using the configuration utility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71 To remove a policy label invocation by using the configuration utility. . . . . . . . . . . . . . . . .71 Configuring and Binding Policies with the Policy Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71 To configure policy bindings by using the Policy Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . .72 To remove unused policies by using the Policy Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
vi
Functions That Return UTF-8 Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99 Terminal Connection Settings for UTF-8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99 Classic Expressions in Default Syntax Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99 Configuring Default Syntax Expressions in a Policy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 To configure a default syntax rule by using the NetScaler command line. . . . . . . . . . . 101 To configure a default syntax policy expression by using the configuration utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101 To test a default syntax expression by using the configuration utility. . . . . . . . . . . . . . . . 102 Configuring Named Default Syntax Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 To configure a named default syntax expression by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104 To configure a named expression by using the configuration utility. . . . . . . . . . . . . . . . . .104 Configuring Default Syntax Expressions Outside the Context of a Policy. . . . . . . . . . . . . . . . 105 To configure a default syntax expression outside a policy by using the NetScaler command line (cache selector example). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
Contents
Encrypting and Decrypting Text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .155 Configuring Encryption. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156 Using the ENCRYPT and DECRYPT Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .157
Default Syntax Expressions: Working with Dates, Times, and Numbers . . . . . . . . . . . . . . . . . . . . . .159
Format of Dates and Times in an Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .160 Expressions for the NetScaler System Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .161 Expressions for SSL Certificate Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .167 Expressions for HTTP Request and Response Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .179 Generating the Day of the Week, as a String, in Short and Long Formats. . . . . . . . . . . . . . . 180 Expression Prefixes for Numeric Data Other Than Date and Time . . . . . . . . . . . . . . . . . . . . . . .181 Converting Numbers to Text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .182 Virtual Server Based Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184
Default Syntax Expressions: Parsing HTTP, TCP, and UDP Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .187
About Evaluating HTTP and TCP Payload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .188 Expressions for Identifying the Protocol in an Incoming IP Packet. . . . . . . . . . . . . . . . . . . . . . . .189 Arguments to the PROTOCOL function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189 Use Case Scenarios. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .190 Expressions for HTTP and Cache-Control Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191 Prefixes for HTTP Headers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191 Operations for HTTP Headers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .198 Prefixes for Cache-Control Headers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .202 Operations for Cache-Control Headers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .202 Expressions for Extracting Segments of URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .206 Expressions for HTTP Status Codes and Numeric HTTP Payload Data Other Than Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .207 SIP Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .209 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 SIP Reference Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Operations for HTTP, HTML, and XML Encoding and Safe Characters . . . . . . . . . . . . . . . .221 Expressions for TCP, UDP, and VLAN Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .225 Expressions for Evaluating a DNS Message and Identifying Its Carrier Protocol. . . . . . . . .230 XPath and HTML, XML, or JSON Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .233 Encrypting and Decrypting XML Payloads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .237 Using the XML_ENCRYPT() and XML_DECRYPT() Functions in Expressions. . . . .239
7
viii
Prefixes for Numeric Data in SSL Certificates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .242 Expressions for SSL Certificates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .243
Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs. . . . . . . . . . . . . . . .249
Expressions for IP Addresses and IP Subnets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .250 Prefixes for IPV4 Addresses and IP Subnets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .250 Operations for IPV4 Addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .251 About IPv6 Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .252 Expression Prefixes for IPv6 Addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253 Operations for IPV6 Prefixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .254 Expressions for MAC Addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .256 Prefixes for MAC Addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .256 Operations for MAC Addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .256 Expressions for Numeric Client and Server Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .257
Contents
To set an HTTP callout parameter to the default value by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .305 To modify or remove an HTTP callout by using the NetScaler command line. . . . . . .306 Parameters for configuring an HTTP callout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .306 To configure an HTTP callout by using the NetScaler configuration utility. . . . . . . . . . .308 Verifying the Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . 09 To view the hits counter for an HTTP callout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . 10 Invoking an HTTP Callout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .310 Avoiding HTTP Callout Recursion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .312 Deployment Scenarios for HTTP Callouts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .314 Example 1: Filtering Clients by Using an IP Blacklist. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .314 Enabling Responder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .314 Creating an HTTP Callout on the NetScaler Appliance. . . . . . . . . . . . . . . . . . . . . . . . .315 Configuring a Responder Policy and Binding it Globally. . . . . . . . . . . . . . . . . . . . . . . .315 Creating an HTTP Callout Agent on the Remote Server. . . . . . . . . . . . . . . . . . . . . . . .316 Example 2: ESI Support for Fetching and Updating Content Dynamically. . . . . . . . . .317 Enabling Rewrite. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .317 Creating an HTTP Callout on the NetScaler Appliance. . . . . . . . . . . . . . . . . . . . . . . . .317 Configuring the Rewrite Action. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .318 Creating the Rewrite Policy and Binding it Globally. . . . . . . . . . . . . . . . . . . . . . . . . . . . .319 Example 3: Access Control and Authentication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . 20 Enabling Responder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .320 Creating an HTTP Callout on the NetScaler Appliance. . . . . . . . . . . . . . . . . . . . . . . . .320 Creating a Responder Policy to Analyze the Response. . . . . . . . . . . . . . . . . . . . . . . .321 Creating an HTTP Callout Agent on the Remote Server. . . . . . . . . . . . . . . . . . . . . . . .322 Example 4: OWA-Based Spam Filtering. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .323 Enabling Responder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .323 Creating an HTTP Callout on the NetScaler Appliance. . . . . . . . . . . . . . . . . . . . . . . . .324 Creating a Responder Action. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .324 Creating a Responder Policy to Invoke the HTTP Callout. . . . . . . . . . . . . . . . . . . . . .325 Creating an HTTP Callout Agent on the Remote Server. . . . . . . . . . . . . . . . . . . . . . . .326
Parameters for configuring a pattern set. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .331 To configure a pattern set by using the NetScaler configuration utility. . . . . . . . . . . . . . .331 Using a Pattern Set. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .332 Pattern Set Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .332
Contents
Redirecting Traffic on the Basis of Traffic Rate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .353 Dropping DNS Requests on the Basis of Traffic Rate. . . . . . . . . . . . . . . . . . . . . . . . . . .353 Redirecting Traffic on the Basis of Traffic Rate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354 Dropping DNS Requests on the Basis of Traffic Rate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
C Summary Examples of Default Syntax Expressions and Policies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .397 D Tutorial Examples of Default Syntax Policies for Rewrite. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .409
Redirecting an External URL to an Internal URL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .410 To redirect an external URL to an internal URL by using the command line. . . . . . . . .410 To redirect an external URL to an internal URL by using the configuration utility. . . 410 Redirecting a Query. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .411 To redirect a query to the appropriate URL using the command line. . . . . . . . . . . . . . . . .411 Redirecting HTTP to HTTPS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .412 To redirect HTTP URLs to HTTPS by using the command line. . . . . . . . . . . . . . . . . . . . . . 412 Removing Unwanted Headers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .412 To create the appropriate Rewrite action by using the NetScaler command line. . . . 412 To create the appropriate Rewrite policy by using the NetScaler command line. . . . 413
xii
To bind the policy globally by using the NetScaler command line. . . . . . . . . . . . . . . . . . . .413 Reducing Web Server Redirects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 To modify directory-level HTTP requests to include the default home page by using the command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .413 Masking the Server Header. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .414 To mask the Server header in responses from the command line. . . . . . . . . . . . . . . . . . .414
xiii
Contents
To bind a classic policy to a virtual server by using the NetScaler command line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .439 Parameters for binding a classic policy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .440 To bind a classic policy globally by using the configuration utility. . . . . . . . . . . . . . . . . . . .440 To bind a classic policy to a virtual server by using the configuration utility. . . . . . . . .441 Viewing Classic Policies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442 To view a classic policy and its binding information by using the NetScaler command line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .442 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .442 Parameters for viewing a classic policy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .442 To view classic policies and policy bindings by using the configuration utility. . . . . . .442 Creating Named Classic Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .443 To create a named classic expression by using the NetScaler command line. . . . . . 443 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .444 Parameters for creating a named classic expression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444 To create a named classic expression by using the configuration utility. . . . . . . . . . . . .444
xiv
Preface
Learn about the Citrix NetScaler collection of documentation, including information about support options and ways to send us feedback. In This Preface: w Formatting Conventions for NetScaler Documentation w Documentation Available on the NetScaler Appliance w Getting Service and Support w NetScaler Documentation Feedback
Monospace
<angle brackets>
[ brackets ]
15
Preface
Convention
Meaning add lb vserver <name> <serviceType> <IPAddress> <port> [ -range <positiveInteger>] Do not type the brackets themselves.
| (vertical bar)
A separator between options in braces or brackets in command statements. For example, the following indicates that you choose one of the following load balancing methods: <lbMethod> = ( ROUNDROBIN | LEASTCONNECTION | LEASTRESPONSETIME | URLHASH | DOMAINHASH | DESTINATIONIPHASH | SOURCEIPHASH | SRCIPDESTIPHASH | LEASTBANDWIDTH | LEASTPACKETS | TOKEN | SRCIPSRCPORTHASH | LRTM | CALLIDHASH | CUSTOMLOAD )
(ellipsis)
You can repeat the previous item or items in command statements. For example, /route:<DeviceName>[ ,] means you can type additional <DeviceNames> separated by commas.
16
17
Preface
18
Chapter 1
19
Chapter 1
20
Citrix NetScaler Policy Configuration and Reference Guide Rule. The rule is a logical expression that enables the NetScaler feature to evaluate a piece of traffic or another object. For example, a rule can enable the NetScaler to determine whether an HTTP request originated from a particular IP address, or whether a Cache-Control header in an HTTP request has the value No-Cache. Default syntax policies can use all of the expressions that are available in a classic policy, with the exception of classic expressions for the SSL VPN client. In addition, default syntax policies enable you to configure more complex expressions. Bindings. To ensure that the NetScaler can invoke a policy when it is needed, you associate the policy, or bind it, to one or more bind points. You can bind a policy globally or to a virtual server. For more information, see About Policy Bindings on page 27. An associated action. An action is a separate entity from a policy. Policy evaluation ultimately results in the NetScaler performing an action. For example, a policy in the integrated cache can identify HTTP requests for .gif or .jpeg files. An action that you associate with this policy determines that the responses to these types of requests are served from the cache. For some features, you configure actions as part of a more complex set of instructions known as a profile. For more information, see Order of Evaluation Based on Traffic Flow on page 28.
System
Classic
21
Chapter 1
Feature Name
Policy Type
How You Use Policies in the Feature certificate-based authentication schemes. You also configure policies in the Auditing function.
DNS
Default
To determine how to perform DNS resolution for requests. To determine when to apply an encryption function and add certificate information to clear text. To provide end-to-end security, after a message is decrypted, the SSL feature re-encrypts clear text and uses SSL to communicate with Web servers.
SSL
Compression
To determine what type of traffic is compressed. To determine whether HTTP responses are cacheable. To configure the behavior of the Responder function. To configure the behavior of the Filter, SureConnect, and Priority Queuing functions. To determine what server or group of servers is responsible for serving responses, based on
Integrated Caching
Default
Responder
Default
Protection Features
Classic
Content Switching
22
Feature Name
Policy Type
How You Use Policies in the Feature characteristics of an incoming request. Request characteristics include device type, language, cookies, HTTP method, content type, and associated cache server.
Classic Exceptions: w Traffic policies support only default syntax policies w Authorization policies support both classic and default syntax policies.
To check for client-side security before users log in and establish a session. Traffic policies, which determine whether single sign-on (SSO) is required, use only the default syntax. Authorization policies authorize users and groups that access intranet resources through the appliance. To determine whether responses are served from a cache or from an origin server. To identify HTTP data that you want to modify before serving. The policies provide rules for modifying the data. For example, you can modify HTTP data to redirect a request to a new home page, or a new server, or a selected server based on the address of the incoming request, or you can modify the data to mask
Cache Redirection
Classic
Rewrite
Default
23
Chapter 1
Feature Name
Policy Type
How You Use Policies in the Feature server information in a response for security purposes. The URL Transformer function identifies URLs in HTTP transactions and text files for the purpose of evaluating whether a URL should be transformed.
Application Firewall
To identify characteristics of traffic and data that should or should not be admitted through the firewall. To define rewrite rules for general Web access using the Access Gateway. To determine how the Access Gateway performs authentication, authorization, auditing, and other functions.
Default
Access Gateway
Classic
About Actions
Actions are steps that the NetScaler takes, depending on the evaluation of the expression in the policy. For example, if an expression in a policy matches a particular source IP address in a request, the action that is associated with this policy determines whether the connection is permitted. 24
Citrix NetScaler Policy Configuration and Reference Guide The types of actions that the NetScaler can take are feature specific. For example, in Rewrite, actions can replace text in a request, change the destination URL for a request, and so on. In Integrated Caching, actions determine whether HTTP responses are served from the cache or an origin server. In some NetScaler features actions are predefined, and in others they are configurable. In some cases, (for example, Rewrite), you configure the actions using the same types of expressions that you use to configure the associated policy rule.
About Profiles
Some NetScaler features enable you to associate profiles, or both actions and profiles, with a policy. A profile is a collection of settings that enable the feature to perform a complex function. For example, in the Application Firewall, a profile for XML data can perform multiple screening operations, such as examining the data for illegal XML syntax or evidence of SQL injection.
25
Chapter 1
Feature
Use of a Profile
Rewrite
You configure URL rewrite actions and add them to a policy. You configure caching and invalidation actions within a policy You select an authentication type, set an authorization action of ALLOW or DENY, or set auditing to SYSLOG or NSLOG. You configure actions within policies for the following functions: w Filter w Compression w Responder w SureConnect
Not used.
Integrated Caching
Not used.
You can configure session profiles with a default timeout and authorization action.
Protection Features
Not used.
SSL
You configure actions within SSL policies The action is implied. For the Authentication function, it is either Allow or Deny. For Auditing, it is Auditing On or Auditing Off. The action is implied. It is either Drop Packets or the location of a DNS server. The action is implied. It is based on a policy that you
Not used.
System
Not used.
DNS
Not used.
SSL Offload
Not used.
26
Feature
Use of a Profile
Compression
Determine the type of compression to apply to the data The action is implied. If a request matches the policy, the request is directed to the virtual server associated with the policy. The action is implied. If a request matches the policy, the request is directed to the origin server.
Not used.
Content Switching
Not used.
Cache Redirection
Not used.
Chapter 1
Introduction to Policies and Expressions Other bind points. The availability of additional bind points depends on type of policy (classic or default syntax), and specifics of the relevant NetScaler feature. For example, classic policies that you configure for the Access Gateway have user and group bind points. For additional information about default syntax policy bindings, see Binding Policies That Use the Default Syntax on page 41 and Configuring a Policy Bank for a Virtual Server on page 65. For additional information about classic policy bindings, see Configuring a Classic Policy on page 432.
Citrix NetScaler Policy Configuration and Reference Guide the NetScaler. At that point, the NetScaler typically applies all matching actions. Integrated Caching, which only applies a final Cache or NoCache action, is an exception. Some policies affect the outcome of other policies. Following are examples: w If a response is served from the integrated cache, some other NetScaler features do not process the response or the request that initiated it. w If the Content Filtering feature prevents a response from being served, no subsequent features evaluate the response. If the Application Firewall rejects an incoming request, no other features can process it.
29
Chapter 1
30
Citrix NetScaler Policy Configuration and Reference Guide w SSL w Cache redirection w VPN (session, traffic, and tunnel traffic) w Content filtering (The responder feature not only provides you with functionality that is equivalent to that provided by the content filtering feature but also surpasses the content filtering feature in the use cases that it supports. Additionally, responder supports the more powerful default syntax for policy expressions.) The following NetScaler features support both classic and default syntax expressions and, therefore, support the conversion of classic expressions to default syntax expressions: w Application Firewall policies w Authorization policies w Named expressions w Compression policies w Content switching policies w User-defined, rule-based tokens/persistency (the rule parameter value that is specified for a load balancing virtual server)
Chapter 1
Introduction to Policies and Expressions In the commands that create the classic named expressions ne_c1 and ne_c2, the tool replaces the names of the expressions with actual default syntax expressions. This action, which corresponds to Step 1 described earlier, results in the following commands: add policy expression ne_c1 "HTTP.REQ.METHOD.EQ(\"GET\")" add policy expression ne_c2 "HTTP.REQ.URL.SUFFIX.EQ(\"htm\")" The filter policy command supports only the classic syntax. Therefore, the conversion tool replaces the classic named expression ne_c1 with the actual classic expression it represents. Note that the tool replaces ne_c1 in the expression for ne_c2, and then replaces ne_c2 in the filter policy with the classic expression. This action, which corresponds to Step 2 described earlier, results in the following command: add filter policy pol1 -rule "METHOD == GET || URL == /*.htm" reqAction YES The compression feature supports both classic and default syntax expressions. Therefore, in the command that creates the compression policy pol2, the conversion tool replaces the expression with a default syntax expression. This action, which corresponds to Step 3 described earlier, results in the following command: add cmp policy pol2 -rule "HTTP.REQ.HEADER(\"Accept \").AFTER_STR(\"text/html\").LENGTH.GT(0)" -resAction COMPRESS The command that creates the compression policy pol3 is unaffected by the conversion process because, after the conversion process is complete, ne_c1 and ne_c2 reference the default syntax expressions that result from Step 1. Client security messages are not supported in the newer default policy format and, therefore, are lost. The SYS.EVAL_CLASSIC_EXPR function is replaced with a default policy expression. The following entities support the SYS.EVAL_CLASSIC_EXPR function: w DNS policies w Rate limit selectors w Cache selectors w Cache policies w Content switching policies w Rewrite policies w URL transformation policies w Responder policies w Application Firewall policies w Authorization policies w Compression policies w CVPN access policies After performing the conversion, the tool saves the changes in a new configuration file. The new configuration file is created in the directory in which the input file exists. The
32
Citrix NetScaler Policy Configuration and Reference Guide name of the new configuration file is the same as the name of the input configuration file except for the string new_ used as a prefix. Conversion warnings are reported in a warning line at the end of the screen output. Additionally, a warning file is created in the directory in which the input configuration file resides. For more information about the warning file and the types of warnings that are reported, see Conversion Warnings on page 34.
Converting Expressions
You can use the nspepi tool to convert a single classic expression to the default syntax. The nspepi tool must be run from the shell prompt on the NetScaler appliance.
To convert a classic expression to the default syntax by using the NetScaler command line interface
At the shell prompt, type: nspepi -e "<classic expression>" Example root@NS# nspepi -e "REQ.HTTP.URL == /*.htm" "HTTP.REQ.URL.REGEX_MATCH(re#/(.*)\.htm#)"
To convert all the classic expressions in a NetScaler configuration file to the default syntax by using the NetScaler command line interface
At the shell prompt, type:
33
Chapter 1
Introduction to Policies and Expressions nspepi -f "<ns config file>" -v Example root@NS# nspepi -f ns.conf OUTPUT: New configuration file created: new_ns.conf OUTPUT: New warning file created: warn_ns.conf WARNINGS: Total number of warnings due to bind commands: 18 WARNINGS: Line numbers which has bind command issues: 305, 306, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 767, 768, 774, 775, 776, 777 root@NS#
Parameters for converting the classic expressions in a NetScaler configuration file to the default syntax
f Specifies that the input is a NetScaler configuration file. This option is mutually exclusive with the -e option, which specifies that the input is a single classic expression. ns config file The full path to the NetScaler configuration file. If the NetScaler configuration file is in the present working directory, the name of the NetScaler configuration file is sufficient. v The verbose option. If this option is specified, the output of the conversion tool is printed to the screen. The configuration file and the warning file are created even if this option is used.
Conversion Warnings
When classic expressions that are included in CLI commands are upgraded to the default syntax, the number of characters in the expression might exceed the 1499character limit. The commands that include expressions longer than 1499 characters fail when the configuration is being applied. You must manually update these commands. In addition, multiple classic policies can be bound to a given bind point with priority 0 or with equal priority, but the default syntax policy infrastructure does not support a priority value of 0 or policies with the same priority at a given bind point. These commands fail when the configuration is being applied. The commands must be updated manually with the correct priority values. The line numbers of lines that threw a warning during conversion are listed at the end of the output in a warning line. In addition, a warning file is created in the same directory as the one in which the old and new configuration files reside. The name of
34
Citrix NetScaler Policy Configuration and Reference Guide the warning file is the same as the name of the input configuration file except that the string warn_ is added as a prefix.
35
Chapter 1
36
Chapter 2
37
Chapter 2
Citrix NetScaler Policy Configuration and Reference Guide that you want the policy to work with, you need to know the format of the data that the policy is analyzing. Next, determine whether the policy is globally applicable, or if it pertains to a particular virtual server. Also consider the effect that the order in which your policies are evaluated (which will be determined by how you bind the policies) will have on the policy that you are about to configure.
39
Chapter 2
Note: At the command line, quote marks within a policy rule (the expression) must be escaped or delimited with the q delimiter. For more information, see Configuring Default Syntax Expressions in a Policy on page 100.
Citrix NetScaler Policy Configuration and Reference Guide the Expression window of the feature-configuration dialog box for the integrated caching or rewrite feature. Following is an example of creating a caching policy. Note that actions for caching policies are built in, so you do not need to configure them separately from the policy. add cache policy BranchReportsCachePolicy -rule q{http.req.url.query.value("actionoverride").contains("branchRepo rts")} -action cache Following is an example of a Rewrite policy and action: add rewrite action myAction1 INSERT_HTTP_HEADER "myHeader" "valueForMyHeader" add rewrite policy myPolicy1 "http.req.url.contains(\"myURLstring \")" myAction1 Note: At the command line, quote marks within a policy rule (the expression) must be escaped or delimited with the q delimiter. For more information, see Configuring Default Syntax Expressions in a Policy on page 100.
41
Chapter 2
Configuring Default Syntax Policies Table 2-1. Feature-Specific Bindings for Policies Feature Name Virtual Servers Configured in the Feature none Policies Configured in the Feature Bind Points Configured for the Policies Global Use of Policies in the Feature
DNS
DNS policies
To determine how to perform DNS resolution for requests. To determine what server or group of servers is responsible for serving responses, based on characteristics of an incoming request. Request characteristics include device type, language, cookies, HTTP method, content type, and associated cache server.
Content Switching Note: This feature can support either or classic policies or policies that use the default syntax, but not both.
Integrated Caching
none
Caching policies
w Global override w Global default w Policy label w Load balancing, content switching, or SSL offload
To determine whether HTTP responses can be stored in, and served from, the NetScaler's integrated cache.
42
Feature Name
Responder
none
Responder policies
w Global override w Global default w Policy label w Load balancing, content switching, or SSL offload virtual server
Rewrite
none
Rewrite policies
w Global override w Global default w Policy label w Load balancing, content switching, or SSL offload virtual server
To identify HTTP data that you want to modify before serving. The policies provide rules for modifying the data. For example, you can modify HTTP data to redirect a request to a selected server based on the address of the incoming request, or to mask server
43
Chapter 2
Feature Name
information in a response for security purposes. URL Transform function in the Rewrite feature none Transformatio n policies w Global override w Global default w Policy label To identify URLs in HTTP transactions and text files for the purpose of evaluating whether a URL should be altered. To determine how the Access Gateway performs authentication , authorization, auditing, and other functions, and to define rewrite rules for general Web access using the Access Gateway.
VPN server
Citrix NetScaler Policy Configuration and Reference Guide 1. Request-time override. When a request flows through a feature, the NetScaler first evaluates request-time override policies for the feature. 2. Request-time Load Balancing virtual server. If policy evaluation cannot be completed after all the request-time override policies have been evaluated, the NetScaler processes request-time policies for load balancing virtual servers. 3. Request-time Content Switching virtual server. If policy evaluation cannot be completed after all the request-time policies for load balancing virtual servers have been evaluated, the NetScaler processes request-time policies for content switching virtual servers. 4. Request-time default. If policy evaluation cannot be completed after all requesttime, virtual server-specific policies have been evaluated, the NetScaler processes request-time default policies. 5. Response-time override. At response time, the NetScaler starts with policies that are bound to the response-time override bind point. 6. Response-time Load Balancing virtual server. If policy evaluation cannot be completed after all response-time override policies have been evaluated, the NetScaler process the response-time policies for load balancing virtual servers. 7. Response-time Content Switching virtual server. If policy evaluation cannot be completed after all policies have been evaluated for load balancing virtual servers, the NetScaler process the response-time policies for content switching virtual servers. 8. Response-time default. If policy evaluation cannot be completed after all responsetime, virtual-server-specific policies have been evaluated, the NetScaler processes response-time default policies.
45
Chapter 2
Configuring Default Syntax Policies 4. Policies that are bound to the global default bind point. To be sure that the policies are evaluated in the intended order, follow these guidelines: w Make sure that the default load balancing vserver is not directly reachable from the outside; for example, the vserver IP address can be 0.0.0.0. w To prevent exposing internal data on the load balancing default vserver, configure a policy to respond with a 503 Service Unavailable status and bind it to the default load balancing vserver.
The policy name, or a dummy policy named NOPOLICY. The NOPOLICY entry controls evaluation flow without processing a rule.
An integer.
If the policy evaluates to TRUE, the NetScaler stores the action that is associated with the policy. If the policy evaluates to FALSE, the NetScaler evaluates the next policy. If the policy is neither TRUE nor FALSE, the NetScaler uses the associated Undef (undefined) action.
46
Citrix NetScaler Policy Configuration and Reference Guide A priority. The most minimal amount of information about evaluation order is a numeric priority level. The lower the number, the higher the priority. A Goto expression. If supplied, the Goto expression indicates the next policy to be evaluated, typically within the same policy bank.. Goto expressions can only proceed forward in a bank. To prevent looping, a policy bank configuration is not valid if a Goto statement points backwards in the bank. Invocation of other policy banks. Any entry can invoke an external policy bank. The NetScaler provides a built-in entity named NOPOLICY that does not have a rule. You can add a NOPOLICY entry in a policy bank when you want to invoke another policy bank, but do not want to process any other rules prior to the invocation. You can have multiple NOPOLICY entries in multiple policy banks. Values for a Goto expression are as follows: NEXT. This keyword selects the policy with the next higher priority level in the current policy bank. An integer. If you supply an integer, it must match the priority level of another policy in the current policy bank. END. This keyword stops evaluation after processing the current policy, and no additional policies in this bank are processed. Blank. If the Goto expression is empty, it is the same as specifying END. A numeric expression. This is a default syntax expression that resolves to a priority number for another policy in the current bank. USE_INVOCATION_RESULT. This phrase can be used only if you are invoking an external policy bank. Entering this phrase causes the NetScaler to perform one of the following actions: w If the final Goto in the invoked policy bank has a value of END or is empty, the invocation result is END, and evaluation stops. w If the final Goto expression in the invoked policy bank is anything other than END, the NetScaler performs a NEXT. The following table illustrates a policy bank that uses Goto statements and policy bank invocations.
47
Chapter 2
Configuring Default Syntax Policies Table 2-3. Example of a Policy Bank That Uses Gotos and External Bank Invocations Policy Name Priority Goto Invocation Policy Bank to Be Invoked None
ClientCertifica tePolicy (rule: does the request contain a client certificate?) SubnetPolicy (rule: is the client from a private subnet?) NOPOLICY
100
300
None
200
NEXT
None
None
300
Request vserver
My_Request_V Server
NOPOLICY
350
Policy Label
My_Policy_Lab el
400
None
None
Citrix NetScaler Policy Configuration and Reference Guide If this is the last entry to be evaluated in this policy bank, the NetScaler proceeds to the next feature.
To bind an Integrated Caching policy globally by using the NetScaler command line
At the NetScaler command prompt, type the following commands to bind an Integrated Chaching policy and verify the configuration: w bind cache global <policyName> -priority <positiveInteger> [-type REQ_OVERRIDE | REQ_DEFAULT | RES_OVERRIDE | RES_DEFAULT] w show cache global Example bind cache global _nonPostReq -priority 100 -type req_default Done > show cache global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 2 2) Done Global bindpoint: RES_DEFAULT Number of bound policies: 1
The type argument is optional to maintain backward compatibility. If you omit the type, the policy is bound to REQ_DEFAULT or RES_DEFAULT, depending on whether the policy rule is a response-time or a request-time expression.
49
Chapter 2
Configuring Default Syntax Policies w bind rewrite global <policyName> <positiveIntegerAsPriority> [-type REQ_OVERRIDE | REQ_DEFAULT | RES_OVERRIDE | RES_DEFAULT] w show rewrite global Example bind rewrite global pol_remove-pdf 100 Done > show rewrite global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 1 2) Done The type argument is optional for globally bound policies, to maintain backward compatibility. If you omit the type, the policy is bound to REQ_DEFAULT or RES_DEFAULT, depending on whether the policy rule is a response-time or a requesttime expression. Global bindpoint: REQ_OVERRIDE Number of bound policies: 1
>
Done
Citrix NetScaler Policy Configuration and Reference Guide w bind responder global <policyName> <positiveIntegerAsPriority> [type OVERRIDE | DEFAULT ] w show responder global Example bind responder global pol404Error1 200 Done > show responder global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 1 Done
To bind an Integrated Caching, Responder, Rewrite, or Compression policy globally by using the configuration utility
1. In the navigation pane, click the name of the feature for which you want to bind the policy. 2. In the details pane, click <Feature Name> policy manager. 3. In the Policy Manager dialog box, select the bind point to which you want to bind the policy (for example, for Integrated Caching, Rewrite, or Compression, you could select Request and Default Global). The Responder does not differentiate between request-time and response-time policies. 4. Click Insert Policy and, from the Policy Name pop-up menu, select the policy name. A priority is assigned automatically to the policy, but you can click the cell in the Priority column and drag it anywhere within the dialog box if you want the policy to be evaluated after other policies in this bank. The priority is automatically reset. Note that priority values within a policy bank must be unique. 51
Chapter 2
Configuring Default Syntax Policies 5. Click Apply Changes. 6. Click Close. A message in the status bar indicates that the policy is binded successfully.
To bind a policy to a load balancing or content switching virtual server by using the NetScaler command line
At the NetScaler command prompt, type the following commands to bind a policy to a load balancing or content switching virtual server and verify the configuration: w bind lb|cs vserver <virtualServerName> -policyName <policyName> priority <positiveInteger> -type REQUEST|RESPONSE w show lb vserver lbvip Example > bind lb vserver lbvip -policyName ns_cmp_msapp -priority 50 Done > show lb vserver lbvip lbvip (8.7.6.6:80) - HTTP Type: ADDRESS State: DOWN Last state change was at Wed Jul 15 05:54:24 2009 (+226 ms) Time since last state change: 28 days, 01:57:26.350 Effective State: DOWN Client Idle Timeout: 180 sec Down state flush: ENABLED Disable Primary Vserver On Down : DISABLED Port Rewrite : DISABLED No. of Bound Services : 0 (Total) 0 (Active) Configured Method: LEASTCONNECTION Mode: IP Persistence: NONE 52
Citrix NetScaler Policy Configuration and Reference Guide Vserver IP and Port insertion: OFF Push: DISABLED Push VServer: Push Multi Clients: NO Push Label Rule: none 1) 2) Done Policy : ns_cmp_msapp Priority:50 Policy : cf-pol Priority:1 Inherited
To bind a policy to an SSL offload virtual server by using the NetScaler command line
At the NetScaler command prompt, type the following commands to bind a policy to an SSL offload virtual server and verify the configuration: bind ssl vserver <virtualServerName> -policyName <policyName> priority <positiveInteger>
Chapter 2
Configuring Default Syntax Policies UndefAction: Use Global Hits: 0 Undef Hits: 0 Bound to: GLOBAL REQ_DEFAULT Priority: 100 GotoPriorityExpression: END
>
Done
To display global policy bindings for Integrated Caching, Rewrite, or Responder by using the configuration utility
1. In the navigation pane, expand the feature that contains the policy that you want to view, and then click Policies. 2. In the details pane, click the policy. Bound policies have a check mark next to them. 3. At the bottom of the page, under Details, next to Bound to, view the entity to which the policy is bound.
To display global policy bindings for DNS or Clientless Access in the Access Gateway by using the configuration utility
1. In the navigation pane, expand DNS, and then click Policies. 2. In the details pane, click Global Bindings.
To display global policy bindings for Content Switching by using the configuration utility
1. In the navigation pane, expand Content Switching, and then click Policies. 2. In detailed pane, select policy. 3. In the details pane, click Show Bindings.
Unbinding a Policy
If you want to re-assign a policy or delete it, you must first remove its binding.
To unbind an integrated caching, rewrite, or compression default syntax policy globally by using the NetScaler command line
At the NetScaler command prompt, type the following commands to unbind an integrated caching, rewrite, or compression default syntax policy globally and verify the configuration:
54
Citrix NetScaler Policy Configuration and Reference Guide w unbind cache|rewrite|cmp global <policyName> [-type req_override| req_default|res_override|res_default] [-priority <positiveInteger>] w show cache|rewrite|cmp global Example > unbind cache global_nonPostReq Done > show cache global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 1 2) Done The priority is required only for the dummy policy named NOPOLICY. Global bindpoint: RES_DEFAULT Number of bound policies: 1
Chapter 2
Configuring Default Syntax Policies Example unbind dns global dfgdfg Done show dns global Policy name : dfgdfggfhg Priority : 100 Goto expression : END Done
To unbind a default syntax policy from a virtual server by using the NetScaler command line
At the NetScaler command prompt, type the following commands to unbind a default syntax policy from a virtual server and verify the configuration: w unbind <featureType> vserver <virtualServerName> -policyName <policyName> [-priority <positiveInteger>] [-type REQUEST| RESPONSE] w show lb vserver lbvip Example unbind cs vserver vs-cont-switch -policyName pol1 Done > show cs vserver vs-cont-switch vs-cont-switch (10.102.29.10:80) - HTTP Type: CONTENT State: UP Last state change was at Wed Aug 19 08:56:55 2009 (+18 ms) Time since last state change: 0 days, 02:47:55.750 Client Idle Timeout: 180 sec Down state flush: ENABLED Disable Primary Vserver On Down : DISABLED Port Rewrite : DISABLED State Update: DISABLED Default: Content Precedence: RULE Vserver IP and Port insertion: OFF Case Sensitivity: ON Push: DISABLED Push VServer: Push Label Rule: none Done The priority is required only for the dummy policy named NOPOLICY.
56
To unbind an integrated caching, responder, rewrite, or compression default syntax policy globally by using the configuration utility
1. In the navigation pane, click the feature with the policy that you want to unbind (for example, Integrated Caching). 2. In the details pane, click <Feature Name> policy manager. 3. In the Policy Manager dialog box, select the bind point with the policy that you want to unbind, for example, Default Global. 4. Click the policy name that you want to unbind, and then click Unbind Policy. 5. Click Apply Changes. 6. Click Close. A message in the status bar indicates that the policy is unbound successfully.
To unbind a default syntax policy from a load balancing or content switching virtual server by using the configuration utility
1. In the navigation pane, expand Load Balancing or Content Switching, and then click Virtual Servers. 2. In the details pane, double-click the virtual server from which you want to unbind the policy. 3. On the Policies tab, in the Active column, clear the check box next to the policy that you want to unbind. 4. Click OK. A message in the status bar indicates that the policy is unbinded successfully.
57
Chapter 2
To create a Content Switching policy label by using the NetScaler command line
At the NetScaler command prompt, type the following commands to create a Content Switching policy label and verify the configuration: 58
Citrix NetScaler Policy Configuration and Reference Guide w add cs policylabel <policyLabelName> http|tcp|rtsp|ssl w show cs policylabel <policyLabelName> Example > add cs policylabel lbl-cs-pol http Done > show cs policylabel lbl-cs-pol Label Name: lbl-cs-pol Label Type: HTTP Number of bound policies: 0 Number of times invoked: 0 Done
Chapter 2
Note: Invoke this policy label from a policy bank. For more information, see Binding a Policy to a Policy Label on page 60.
Citrix NetScaler Policy Configuration and Reference Guide END: Stop evaluation. USE_INVOCATION_RESULT: Applicable if this entry invokes another policy bank. If the final Goto in the invoked bank has a value of END, evaluation stops. If the final Goto is anything other than END, the current policy bank performs a NEXT. Positive number: The priority number of the next policy to be evaluated. Numeric expression: An expression that produces the priority number of the next policy to be evaluated. The Goto can only proceed forward in a policy bank. If you omit the Goto expression, it is the same as specifying END. Invocation Type Designates a policy bank type. The value can be one of the following: Request Vserver: Invokes request-time policies that are associated with a virtual server. Response Vserver: Invokes response-time policies that are associated with a virtual server. Policy label: Invokes another policy bank, as identified by the policy label for the bank. Invocation Name The name of a virtual server or a policy label, depending on the value that you specified for the Invocation Type.
61
Chapter 2
Configuring Default Syntax Policies For configuring policy labels from the NetScaler command line, note the following elaborations of the command syntax: w gotoPriorityExpression is configured as described in Entries in a Policy Bank on page 46. w The type argument is required. This is unlike binding a conventional policy, where this argument is optional. w You can invoke the bank of policies that are bound to a virtual server by using the same method as you use for invoking a policy label.
To invoke a policy label from a Rewrite policy bank with a NOPOLICY entry by using the NetScaler command line
At the NetScaler command prompt, type the following commands to invoke a policy label from a Rewrite policy bank with a NOPOLICY entry and verify the configuration: w bind rewrite global NOPOLICY <priority> -gotoPriorityExpression <gotopriorityExpression> -type REQ_OVERRIDE|REQ_DEFAULT|
62
Citrix NetScaler Policy Configuration and Reference Guide RES_OVERRIDE|RES_DEFAULT -invoke reqvserver|resvserver| policylabel <policyLabelName>|<vserverName> w show rewrite global Example > bind rewrite global NOPOLICY 100 -type REQ_DEFAULT -invoke policylabel lbl-rewrt-pol Done > show rewrite global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 1 2) Done Global bindpoint: REQ_OVERRIDE Number of bound policies: 1
To invoke a policy label from an Integrated Caching policy bank by using the NetScaler command line
At the NetScaler command prompt, type the following commands to invoke a policy label from an Integrated Caching policy bank and verify the configuration: w bind cache global NOPOLICY -priority <priority> gotoPriorityExpression <gotopriorityExpression> -type REQ_OVERRIDE|REQ_DEFAULT|RES_OVERRIDE|RES_DEFAULT -invoke reqvserver|resvserver|policylabel <policyLabelName>| <vserverName> w show cache global Example bind cache global NOPOLICY -priority 100 gotoPriorityExpression END -type REQ_DEFAULT -invoke policylabel lbl-cache-pol Done > show cache global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 2 2) Done Global bindpoint: RES_DEFAULT Number of bound policies: 1
To invoke a policy label from a Responder policy bank by using the NetScaler command line
At the NetScaler command prompt, type the following commands to invoke a policy label from a Responder policy bank and verify the configuration: w bind responder global NOPOLICY <priority> <gotopriorityExpression> type OVERRIDE|DEFAULT -invoke vserver|policylabel <policyLabelName>|<vserverName>
63
Chapter 2
Configuring Default Syntax Policies w show responder global Example > bind responder global NOPOLICY 100 NEXT -type DEFAULT -invoke policylabel lbl-respndr-pol Done > show responder global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 2 Done
To add policies to a virtual server policy bank by using the NetScaler command line
At the NetScaler command prompt, type the following commands to add policies to a virtual server policy bank and verify the configuration: w bind lb|cs vserver <virtualServerName> <serviceType> [-policyName <policyName>] [-priority <positiveInteger>] [gotoPriorityExpression <expression>] [-type REQUEST|RESPONSE] w show lb|cs vserver <virtualServerName> Example add lb vserver vs-cont-sw TCP Done show lb vserver vs-cont-sw vs-cont-sw (0.0.0.0:0) - TCP Type: ADDRESS State: DOWN Last state change was at Wed Aug 19 10:04:02 2009 (+279 ms) Time since last state change: 0 days, 00:02:14.420 Effective State: DOWN Client Idle Timeout: 9000 sec Down state flush: ENABLED Disable Primary Vserver On Down : DISABLED No. of Bound Services : 0 (Total) 0 (Active) Configured Method: LEASTCONNECTION Mode: IP Persistence: NONE Connection Failover: DISABLED Done
To invoke a policy label from a virtual server policy bank with a NOPOLICY entry by using the NetScaler command line
At the NetScaler command prompt, type the following commands to invoke a policy label from a virtual server policy bank with a NOPOLICY entry and verify the configuration: w bind lb|cs vserver <virtualServerName> -policyName NOPOLICY_REWRITE| NOPOLICY_CACHE|NOPOLICY_RESPONDER -priority <integer> -type REQUEST|RESPONSE -gotoPriorityExpression <gotopriorityExpression> -invoke reqVserver|resVserver| policyLabel <vserverName>|<labelName> w show lb vserver 65
Chapter 2
Configuring Default Syntax Policies Example > bind lb vserver vs-cont-sw -policyname NOPOLICY-REWRITE priority 200 -type REQUEST -gotoPriorityExpression NEXT -invoke policyLabel lbl-rewrt-pol Done
66
To invoke a rewrite or integrated caching policy label by using the NetScaler command line
At the NetScaler command prompt, type the following commands to invoke a rewrite or integrated caching policy label and verify the configuration: w bind cache|rewrite global <policy_Name> -priority <positive_integer> [-gotoPriorityExpression <expression>] -type REQ_OVERRIDE| REQ_DEFAULT|RES_OVERRIDE|RES_DEFAULT] -invoke reqvserver| resvserver|policylabel <label_name> w show cache|rewrite global Example > bind cache global _nonPostReq2 -priority 100 -type req_override -invoke policylabel lbl-cache-pol Done > show cache global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 2 2) 3) Done Global bindpoint: RES_DEFAULT Number of bound policies: 1 Global bindpoint: REQ_OVERRIDE Number of bound policies: 1
67
Chapter 2
To invoke a Virtual Server Policy Bank by using the NetScaler command line
At the NetScaler command prompt, type the following commands to invoke a Virtual Server Policy Bank and verify the configuration: w bind lb vserver <vserver_name> -policyName <policy_Name> -priority <positive_integer> [-gotoPriorityExpression <expression>] -type REQUEST|RESPONSE -invoke reqvserver|resvserver|policylabel <policy_Label_Name> w bind lb vserver <vserver_name> Example > bind lb vserver lbvip -policyName ns_cmp_msapp -priority 100 Done > show lb vserver lbvip lbvip (8.7.6.6:80) - HTTP Type: ADDRESS State: DOWN Last state change was at Wed Jul 15 05:54:24 2009 (+166 ms) Time since last state change: 28 days, 06:37:49.250 Effective State: DOWN Client Idle Timeout: 180 sec Down state flush: ENABLED Disable Primary Vserver On Down : DISABLED Port Rewrite : DISABLED 68
Citrix NetScaler Policy Configuration and Reference Guide No. of Bound Services : 0 (Total) Configured Method: LEASTCONNECTION Mode: IP Persistence: NONE Vserver IP and Port insertion: OFF Push: DISABLED Push VServer: Push Multi Clients: NO Push Label Rule: none 1) CSPolicy: pol-cont-sw Priority: 100 Hits: 0 1) 2) 3) Done > 0 (Active)
CSVserver: vs-cont-sw
Policy : pol-ssl Priority:0 Policy : ns_cmp_msapp Priority:100 Policy : cf-pol Priority:1 Inherited
To remove a rewrite or integrated caching policy label by using the NetScaler command line
At the NetScaler command prompt, type the following commands to remove a rewrite or integrated caching policy label and verify the configuration: w unbind rewrite|cache global NOPOLICY -priority <positiveInteger> type REQ_OVERRIDE|REQ_DEFAULT|RES_OVERRIDE|RES_DEFAULT w show rewrite|cache global Example > unbind rewrite global NOPOLICY -priority 100 -type REQ_OVERRIDE Done > show rewrite global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 1 Done
Chapter 2
Configuring Default Syntax Policies Done > show responder global 1) Global bindpoint: REQ_DEFAULT Number of bound policies: 1 Done
To remove a Virtual Server policy label by using the NetScaler command line
At the NetScaler command prompt, type the following commands to remove a Virtual Server policy label and verify the configuration: w unbind lb|cs vserver <virtualServerName> -policyName NOPOLICYREWRITE|NOPOLICY-RESPONDER|NOPOLICY-CACHE -type REQUEST| RESPONSE -priority <positiveInteger> w show lb|cs vserver Example > unbind lb vserver lbvip -policyName ns_cmp_msapp -priority 200 Done > show lb vserver lbvip lbvip (8.7.6.6:80) - HTTP Type: ADDRESS State: DOWN Last state change was at Wed Jul 15 05:54:24 2009 (+161 ms) Time since last state change: 28 days, 06:47:54.600 Effective State: DOWN Client Idle Timeout: 180 sec Down state flush: ENABLED Disable Primary Vserver On Down : DISABLED Port Rewrite : DISABLED No. of Bound Services : 0 (Total) 0 (Active) Configured Method: LEASTCONNECTION Mode: IP Persistence: NONE Vserver IP and Port insertion: OFF Push: DISABLED Push VServer: Push Multi Clients: NO Push Label Rule: none 1) CSPolicy: pol-cont-sw Priority: 100 Hits: 0 1) 2) Done CSVserver: vs-cont-sw
Inherited
70
To invoke a policy label or virtual server policy bank by using the configuration utility
1. Bind a policy, as described in Binding a Policy Globally on page 49, Binding a Policy to a Virtual Server on page 52, or Binding a Policy to a Policy Label on page 60. Alternatively, you can enter a NOPOLICY dummy entry instead of a policy name. You do this if you do not want to evaluate a policy before evaluating the policy bank. 2. In the Invoke field, select the name of the policy label or virtual server policy bank that you want to evaluate if traffic matches the bound policy. A message in the status bar indicates that the policy label or virtual server policy bank is invoked successfully.
71
Chapter 2
Note: Note that when you delete the policy, the NetScaler searches the Goto Expression values of other policies in the bank. If any of these Goto Expression values match the priority level of the deleted policy, they are removed.
Citrix NetScaler Policy Configuration and Reference Guide updated automatically. For example, if you change a priority value of 10 to 100, all policies with a Goto Expression value of 10 are updated to the value 100. 8. To change the policy, action, or policy bank invocation for an row in the table, click the down arrow to the right of the entry and do one of the following: To change the policy, select another policy name or select New Policy and follow the steps in Creating or Modifying a Policy on page 38. To change the Goto Expression, select Next, End, USE_INVOCATION_RESULT, or select more and enter an expression whose result returns the priority level of another entry in this policy bank. To modify an invocation, select an existing policy bank, or click New Policy Label and follow the steps in Binding a Policy to a Policy Label on page 60. 9. To unbind a policy or a policy label invocation from this bank, click any field in the row that contains the policy or policy label, and then click Unbind Policy. 10. When you are done, click Apply Changes. A message in the status bar indicates that the policy is bound successfully.
73
Chapter 2
74
Chapter 3
75
Chapter 3
Expression Characteristics
Policies and a few other entities include rules that the NetScaler uses to evaluate a packet in the traffic flowing through it, to extract data from the NetScaler system itself, to send a request (a callout) to an external application, or to analyze another piece of data. A rule takes the form of a logical expression that is compared against traffic and ultimately returns values of TRUE or FALSE. The elements of the rule can themselves return TRUE or FALSE, string, or numeric values. Before configuring a default syntax expression, you need to understand the characteristics of the data that the policy or other entity is to evaluate. For example, when working with the Integrated Caching feature, a policy determines what data can be stored in the cache. With Integrated Caching, you need to know the URLs, headers, and other data in the HTTP requests and responses that the NetScaler receives. With this knowledge, you can configure policies that match the actual data and enable the NetScaler to manage caching for HTTP traffic. This information helps you determine the type of expression that you need to configure in the policy.
Citrix NetScaler Policy Configuration and Reference Guide This operator causes the NetScaler to evaluate any HTTP requests that contain a Content-Type header, and in particular, to determine if the value of this header is equal to the string text/html. For more information, see Operations on page 79 <compound-operator> is a Boolean or arithmetic operator that forms a compound expression from multiple prefix or prefix.operation elements. For example, consider the following expression: http.req.header("Content-Type").eq("text/html") && http.req.url.contains(".html")
Prefixes
An expression prefix represents a discrete piece of data. For example, an expression prefix can represent an HTTP URL, an HTTP Cookie header, or a string in the body of an HTTP POST request. An expression prefix can identify and return a wide variety of data types, including the following: w A client IP address in a TCP/IP packet w NetScaler system time w An external callout over HTTP w A TCP or UDP record type In most cases, an expression prefix begins with one of the following keywords: CLIENT: Identifies a characteristic of the client that is either sending a request or receiving a response, as in the following examples: w The prefix client.ip.dst designates the destination IP address in the request or response. w The prefix client.ip.src designates the source IP address. HTTP: Identifies an element in an HTTP request or a response, as in the following examples: w The prefix http.req.body(integer) designates the body of the HTTP request as a multiline text object, up to the character position designated in integer. w The prefix http.req.header("header_name") designates an HTTP header, as specified in header_name. w The prefix http.req.url designates an HTTP URL in URL-encoded format. SERVER: Identifies an element in the server that is either processing a request or sending a response. 77
Chapter 3
Configuring Default Syntax Expressions: Getting Started SYS: Identifies a characteristic of the NetScaler that is processing the traffic. Note: Note that DNS policies support only SYS, CLIENT, and SERVER objects. In addition, in the Access Gateway, the Clientless VPN function can use the following types of prefixes: TEXT: Identifies any text element in a request or a response. TARGET: Identifies the target of a connection. URL: Identifies an element in the URL portion of an HTTP request or response. As a general rule of thumb, any expression prefix can be a self-contained expression. For example, the following prefix is a complete expression that returns the contents of the HTTP header specified in the string argument (enclosed in quotation marks): http.res.header.("myheader") Or you can combine prefixes with simple operations to determine TRUE and FALSE values. For example, the following returns a value of TRUE or FALSE: http.res.header.("myheader").exists You can also use complex operations on individual prefixes and multiple prefixes within an expression, as in the following example: http.req.url.length + http.req.cookie.length <= 500 Which expression prefixes you can specify depends on the NetScaler feature. The following table describes the expression prefixes that are of interest on a per-feature basis Table 3-1. Permitted Types of Expression Prefixes in Various NetScaler Features Feature Types of Expression Prefix Used in the Feature SYS, CLIENT, SERVER HTTP, SYS, CLIENT HTTP, SYS, CLIENT HTTP, SYS, CLIENT, SERVER, URL, TEXT, TARGET, VPN
78
Feature
Types of Expression Prefix Used in the Feature HTTP, SYS, CLIENT, SERVER HTTP, SYS, CLIENT, SERVER, URL, TEXT, TARGET, VPN
Note: For details on the permitted expression prefixes in a feature, see the documentation for that feature.
Single-Element Expressions
The simplest type of default syntax expression contains a single element. This element can be one of the following: w true. A default syntax expression can consist simply of the value true. This type of expression always returns a value of TRUE. It is useful for chaining policy actions and triggering Goto expressions. w false. A default syntax expression can consist simply of the value false. This type of expression always returns a value of FALSE. w A prefix for a compound expression. For example, the prefix HTTP.REQ.HOSTNAME is a complete expression that returns a host name and HTTP.REQ.URL is a complete expression that returns a URL. The prefix could also be used in conjunction with operations and additional prefixes to form a compound expression.
Operations
In most expressions, you also specify an operation on the data that the prefix identifies. For example, suppose that you specify the following prefix: http.req.url This prefix extracts URLs in HTTP requests. This expression prefix does not require any operators to be used in an expression. However, when you configure an expression that processes HTTP request URLs, you can specify operations that analyze particular characteristics of the URL. Following are a few possibilities: w Search for a particular host name in the URL. w Search for a particular path in the URL. w Evaluate the length of the URL. w Search for a string in the URL that indicates a time stamp and convert it to GMT. The following is an example of a prefix that identifies an HTTP header named Server and an operation that searches for the string IIS in the header value: 79
Chapter 3
Configuring Default Syntax Expressions: Getting Started http.res.header("Server").contains("IIS") Following is an example of a prefix that identifies host names and an operation that searches for the string www.mycompany.com as the value of the name: http.req.hostname.eq("www.mycompany.com")
80
Citrix NetScaler Policy Configuration and Reference Guide Table 3-3. Basic Types of Operations Operation Type Text operations Description Match individual strings and sets of strings with any portion of a target. The target can be an entire string, the start of a string, or any portion of text in between the start and the end of the string. For example, you can extract the string "XYZ" from "XYZSomeText". Or, you can compare an HTTP header value with an array of different strings. You can also transform text into another type of data. Following are examples: w Transform a string into an integer value w Create a list from the query strings in a URL w Transform a string into a time value Numeric operations Numeric operations include applying arithmetic operators, evaluating content length, the number of items in a list, dates, times, and IP addresses.
Chapter 3
Configuring Default Syntax Expressions: Getting Started You can use parentheses to control the order of evaluation in a compound expression.
82
Citrix NetScaler Policy Configuration and Reference Guide Table 3-4. String-Based Operations for Compound Default Syntax Expressions All string operations Operations that produce a string value str + str Concatenates the value of the expression on the left of the operator with the value on the right. Following is an example: http.req.hostname + http.req.url.protocol str + num Concatenates the value of the expression on the left of the operator with a numeric value on the right. Following is an example: http.req.hostname + http.req.url.content_length num + str Concatenates the numeric value of the expression on the left side of the operator with a string value on the right. Following is an example: http.req.url.content_length + http.req.url.hostname str + ip Concatenates the string value of the expression on the left side of the operator with an IP address value on the right. Following is an example: http.req.hostname + 10.00.000.00 ip + str Concatenates the IP address value of the expression on the left of the operator with a string value on the right.Following is an example: client.ip.dst + http.req.url.hostname str1 ALT str2 Uses the string1 or string2 value that is derived from the expression on either side of the operator, as long as neither
83
Chapter 3
All string operations of these expressions is a compound expressions. Following is an example: http.req.hostname alt client.ip.src Operations on strings that produce a result of TRUE or FALSE str == str Evaluates whether the strings on either side of the operator are the same. Following is an example: http.req.header("myheader") == http.res.header("myheader") str <= str Evaluates whether the string on the left side of the operator is the same as the string on the right, or precedes it alphabetically. Evaluates whether the string on the left side of the operator is the same as the string on the right, or follows it alphabetically. Evaluates whether the string on the left side of the operator precedes the string on the right alphabetically. Evaluates whether the string on the left side of the operator follows the string on the right alphabetically. Evaluates whether the strings on either side of the operator are different.
Logical operations on strings bool && bool This operator is a logical AND. When evaluating the components of the compound expression, all components that are joined by the AND must evaluate to TRUE. Following is an example:
84
All string operations http.req.method.eq(GET) && http.req.url.query.contains("v iewReport && my_pagelabel") bool || bool This operator is a logical OR. When evaluating the components of the compound expression, if any component of the expression that is joined by the OR evaluates to TRUE, the entire expression is TRUE. Following is an example: http.req.url.contains(".js") || http.res.header.("ContentType").contains("javascript") !bool Performs a logical NOT on the expression.
num * num
85
Chapter 3
Operator
Description client.interface.rxthroughput * 9
num / num
Divide the value of the expression on the left of the operator by the value of the expression on the right. Calculate the modulo, or the numeric remainder on a division of the value of the expression on the left of the operator by the value of the expression on the right. For example, the values "15 mod 4" equals 3, and "12 mod 4" equals 0.
num % num
~number
Returns a number after applying a bitwise logical negation of the number. The following example assumes that numeric.expression returns 12 (binary 1100): ~numeric.expression. The result of applying the ~ operator is -11 (a binary 1110011, 32 bits total with all ones to the left). Note that all returned values of less than 32 bits before applying the operator implicitly have zeros to the left to make them 32 bits wide.
number ^ number
Compares two bit patterns of equal length and performs an XOR operation on each pair of corresponding bits in each number argument, returning 1 if the bits are different, and 0 if they are the same. Returns a number after applying a bitwise XOR to the integer argument and the current number value. If the values in the bitwise comparison are the same, the returned value is a 0. The following example assumes that numeric.expression1 returns 12 (binary 1100) and numeric.expression2 returns 10 (binary 1010): numeric.expression1 ^ numeric.expression2 The result of applying the ^ operator to the entire expression is 6 (binary 0110). Note that all returned values of less than 32 bits before applying the operator implicitly have zeros to the left to make them 32 bits wide.
number | number
Returns a number after applying a bitwise OR to the number values. If either value in the bitwise comparison is a 1, the returned value is a 1. The following example assumes that numeric.expression1 returns 12 (binary 1100) and numeric.expression2 returns 10 (binary 1010): numeric.expression1 | numeric.expression2
86
Operator
Description The result of applying the | operator to the entire expression is 14 (binary 1110). Note that all returned values of less than 32 bits before applying the operator implicitly have zeros to the left to make them 32 bits wide.
Compares two bit patterns of equal length and performs a bitwise AND operation on each pair of corresponding bits, returning 1 if both of the bits contains a value of 1, and 0 if either bits are 0. The following example assumes that numeric.expression1 returns 12 (binary 1100) and numeric.expression2 returns 10 (binary 1010): numeric.expression1 & numeric.expression2 The whole expression evaluates to 8 (binary 1000). Note that all returned values of less than 32 bits before applying the operator implicitly have zeros to the left to make them 32 bits wide.
Returns a number after a bitwise left shift of the number value by the right-side number argument number of bits. Note that the number of bits shifted is integer modulo 32. The following example assumes that numeric.expression1 returns 12 (binary 1100) and numeric.expression2 returns 3: numeric.expression1 << numeric.expression2 The result of applying the LSHIFT operator is 96 (a binary 1100000). Note that all returned values of less than 32 bits before applying the operator implicitly have zeros to the left to make them 32 bits wide.
Returns a number after a bitwise right shift of the number value by the integer argument number of bits. Note that the number of bits shifted is integer modulo 32. The following example assumes that numeric.expression1 returns 12 (binary 1100) and numeric.expression2 returns 3: numeric.expression1 >> numeric.expression2 The result of applying the RSHIFT operator is 1 (a binary 0001). Note that all returned values of less than 32 bits before applying the operator implicitly have zeros to the left to make them 32 bits wide.
87
Chapter 3
Configuring Default Syntax Expressions: Getting Started Table 3-6. Numeric Operators That Produce a Result of TRUE or FALSE Operator num == num Description Determine if the value of the expression on the left of the operator is equal to the value of the expression on the right. Determine if the value of the expression on the left of the operator is not equal to the value of the expression on the right. Determine if the value of the expression on the left of the operator is greater than the value of the expression on the right. Determine if the value of the expression on the left of the operator is less than the value of the expression on the right. Determine if the value of the expression on the left of the operator is greater than or equal to the value of the expression on the right. Determine if the value of the expression on the left of the operator is less than or equal to the value of the expression on the right
num != num
Citrix NetScaler Policy Configuration and Reference Guide In compound expressions, the following standard arithmetic and logical operators can be used for the double and unsigned long data types: w +, -, *, and / w %, ~, ^, &, |, <<, and >> (do not apply to double) w ==, !=, >, <, >=, and <= All of these operators have the same meaning as in the C programming language. In all cases of mixed operations between operands of type integer, unsigned long, and double, type promotion is performed so that the operation can be performed on operands of the same type. A type of lower precedence is automatically promoted to the type of the operand with the highest precedence involved in the operation. The order of precedence (higher to lower) is as follows: w Double w Unsigned long w Integer Therefore, an operation that returns a numeric result returns a result of the highest type involved in the operation. For example, if the operands are of type integer and unsigned long, the integer operand is automatically converted to type unsigned long. This type conversion is performed even in simple expressions in which the type of data identified by the expression prefix does not match the type of data that is passed as the argument to the function. To illustrate such an example, in the operation HTTP.REQ.CONTENT_LENGTH.DIV(3ul), the integer returned by the prefix HTTP.REQ.CONTENT_LENGTH is automatically converted to unsigned long (the type of the data passed as the argument to the DIV() function), and an unsigned long division is performed. Similarly, the argument can be promoted in an expression. For example, HTTP.REQ.HEADER("myHeader").TYPECAST_DOUBLE_AT.DIV(5) promotes the integer 5 to type double and performs double-precision division. The following table describes the arithmetic and Boolean functions that can be used with the integer, unsigned long, and double data types. For information about expressions for casting data of one type to data of another type, see Typecasting Data on page 277. Function <prefix>.ADD(<integer>| <unsigned long>|<double>) Description Adds the argument to the value of the expression prefix and returns the result. Example: http.req.content_length.add(10 )
89
Chapter 3
Description Subtracts the argument from the value of the prefix and returns the result. Example: http.req.header.length.sub(10)
Divides the value of the prefix by the argument and returns the quotient. Example: http.req.content_length.div(2)
Multiplies the value of the prefix by the argument and returns the product. Example: http.req.content_length.mul(2)
Returns a Boolean TRUE if the value of the prefix is greater than or equal to the lower value argument and less than or equal to the higher value argument. Example: http.req.content_length.betwee n(5, 500)
Returns a Boolean TRUE if the value of the prefix is equal to the argument. Example: http.req.content_length.eq(50)
Returns a Boolean TRUE if the value of the prefix is not equal to the argument. Example: http.req.content_length.ne(50)
Returns a Boolean TRUE if the value of the prefix is greater than or equal to the argument.
90
Function
Returns a Boolean TRUE if the value of the prefix is greater than the argument. Example: http.req.content_length.gt(500 )
Returns a Boolean TRUE if the value of the prefix is less than or equal to the argument. Example: http.req.content_length.le(5)
Returns a Boolean TRUE if the value of the prefix is less than the argument. Example: http.req.content_length.lt(5)
<prefix>.NEG
Returns the negative of the value of the prefix. This function cannot be used with a prefix that returns data of type unsigned long. Example: http.req.content_length.neg If the content length is 30 characters, the NEG function in the above example returns a value of -30.
Returns the result of a bitwise AND operation performed on the binary equivalents of the argument and the value returned by the prefix. The bitwise AND operation operates on each pair of corresponding bits in the pair of bit strings. The operation returns
91
Chapter 3
Function
Description 1 only if both bits are equal to 1. If either bit is 0, or if both bits are 0, the operation returns 0. If the binary equivalent of an operand contains fewer than 32 bits, the function implicitly adds leading zeros to make the operand 32 bits wide before performing the operation. The BITAND function cannot be used with the double data type. Example: http.req.header (\"test \").contains_index(\"patternse t1\").bitand(4) In the above example, assume that the index returned by the CONTAINS_INDEX pattern set function is an integer value of 12. The BITAND function performs a bitwise AND operation between the binary value of 12, which is 00000000000000000000000000001100 (32 bits wide) and the binary value of 4, which is 00000000000000000000000000001100 (32 bits wide). The resulting bit string that the function returns is 00000000000000000000000000000100, whose decimal equivalent is 4. An ampersand (&) performs a similar function to BITAND but takes two expressions as operands rather than an expression (the prefix) and the argument.
<prefix>.BITNEG
Returns the value that results from a bitwise negation of the value of the prefix. The data type of the value that is returned is the same as that of the value that would otherwise be returned by the prefix. This function cannot be used with a prefix that returns data of type double. If the binary equivalent of an operand contains fewer than 32 bits, the function implicitly adds leading zeros to make the operand 32 bits wide before performing the operation.
92
Function
Description Example: http.req.header(\"test \").contains_index(\"patternse t1\").bitneg In the above example, assume that the index returned by the CONTAINS_INDEX pattern set function is an integer value of 12, whose binary value is 00000000000000000000000000001100 (32 bits wide). The BITNEG function returns 11111111111111111111111111110011, which represents an integer value of - 13. A tilde (~) performs a similar function to that of BITNEG but takes another expression as an argument, instead of operating on an integer prefix expression.
Returns the result of a bitwise OR operation performed on the value of the prefix and the argument. The function returns 1 if either or both bits in a corresponding pair are set to 1. If both bits are 0, the function returns 0. The BITOR function cannot be used with the double data type. If the binary equivalent of an operand contains fewer than 32 bits, the function implicitly adds leading zeros to make the operand 32 bits wide before performing the operation. Example: http.req.header (\"test \").contains_index(\"patternse t1\").bitor(7) In the above example, assume that the index returned by the CONTAINS_INDEX pattern set function is an integer value of 9. The BITOR function performs a bitwise OR operation on the binary value of 9, which is 00000000000000000000000000001001 (32 bits wide), and the binary value of 7,
93
Chapter 3
Function
Description which is 00000000000000000000000000000111 (32 bits wide). The function returns 00000000000000000000000000001111, which represents an integer value of 15. The pipe (|) performs a similar function to that of BITOR but takes two expressions as operands rather than an integer or unsigned long (the argument to the function) and an expression prefix.
<prefix>.BITXOR(<integer>|<unsigned long>)
Returns the result of a bitwise EXLUSIVE-OR (XOR) operation performed on the value of the prefix and the value of the argument. If the values of a pair of corresponding bits are the same, the function returns 0. If the bits do not have the same value, the function returns 1. If the binary equivalent of an operand contains fewer than 32 bits, the function implicitly adds leading zeros to make the operand 32 bits wide before performing the operation. The BITXOR function cannot be used with the double data type. Example: http.req.header (\"test \").contains_index(\"patternse t1\").bitxor(8) In the above example, assume that the index returned by the CONTAINS_INDEX pattern set function is an integer value of 15. The BITOR function performs a bitwise XOR operation on the binary value of 15, which is 00000000000000000000000000001111 (32 bits wide), and the binary value of 8, which is 00000000000000000000000000001000 (32 bits wide). The function returns 00000000000000000000000000000111, which represents an integer value of 7.
94
Function
Description A caret (^) performs a similar function to that of BITXOR but takes two expressions as operands rather than an expression and an argument.
Returns the result of a bitwise left shift operation on the value of the prefix. The number of shifts is <integer> modulo 32. Each leftward shift effectively multiplies the value of the prefix by 2. If the binary equivalent of an operand contains fewer than 32 bits, the function implicitly adds leading zeros to make the operand 32 bits wide before performing the operation. This function cannot be used with a prefix that returns data of type double. Example: http.req.header (\"test \").contains_index(\"pat1\").l shift(2) Assume that the index that is returned by the CONTAINS_INDEX operator is 10. The left shift operator drops the two leftmost bits in the binary value of 10, which is 00000000000000000000000000001010 (32 bits wide), and adds two zeros to the right. The result is 00000000000000000000000000101000, which represents a decimal value of 40. A double less-than (<<) performs a similar function to that of LSHIFT but takes two expressions as operands, instead of an expression and an argument.
Returns the result of a bitwise right shift operation on the value of the prefix. The number of shifts is <integer> modulo 32. Each rightward shift effectively divides the value of the prefix by 2. If the binary equivalent of an operand contains less than 32 bits, the function implicitly adds leading zeros before 95
Chapter 3
Function
Description performing the operation to make the operand 32 bits wide. This function cannot be used with a prefix that returns data of type double. Example: http.req.header (\"test \").contains_index(\"pat1\").R shift(2) Assume that the index that is returned by the CONTAINS_INDEX operator is 320. The left shift operator drops the two rightmost bits in the binary value of 320, which is 00000000000000000000000101000000 (32 bits wide), and adds two zeros to the right. The result is 00000000000000000000000001010000, which represents an integer value of 80. A double greater-than (>>) performs the same function as RSHIFT but takes two expressions as operands, instead of an expression and an argument.
Divides the value returned by the preceding function by its argument and returns the remainder. The argument must be a non-zero value.
96
Citrix NetScaler Policy Configuration and Reference Guide In an expression, the SET_CHAR_SET() function must be introduced at the point in the expression after which data processing must be carried out in the specified character set. For example, in the expression HTTP.REQ.BODY(1000).AFTER_REGEX(re/following example/).BEFORE_REGEX(re/In the preceding example/).CONTAINS_ANY("Greek_ alphabet"), if the strings stored in the pattern set "Greek_alphabet" are in UTF-8, you must include the SET_CHAR_SET(UTF_8) function immediately before the CONTAINS_ANY("<string>") function, as follows: HTTP.REQ.BODY(1000).AFTER_REGEX(re/following example/).BEFORE_REGEX(re/In the preceding example/).SET_CHAR_SET(UTF_8).CONTAINS_ANY("Greek_ alphabet") The SET_CHAR_SET() function sets the character set for all further processing (that is, for all subsequent functions) in the expression unless it is overridden later in the expression by another SET_CHAR_SET() function that changes the character set. Therefore, if all the functions in a given simple expression are intended for UTF-8, you can include the SET_CHAR_SET(UTF_8) function immediately after functions that identify text (for example, the HEADER("<name>") or BODY(<int>) funtions). In the second example that follows the first paragraph above, if the ASCII arguments passed to the AFTER_REGEX() and BEFORE_REGEX() functions are changed to UTF-8 strings, you can include the SET_CHAR_SET(UTF_8) function immediately after the BODY(1000) function, as follows: HTTP.REQ.BODY(1000).SET_CHAR_SET(UTF_8).AFTER_REGEX(re/ Bcher/).BEFORE_REGEX(re/ Wrterbuch/).CONTAINS_ANY("Greek_alphabet") The UTF-8 character set is a superset of the ASCII character set, so expressions configured for the ASCII character set continue to work as expected if you change the character set to UTF-8.
97
Chapter 3
Configuring Default Syntax Expressions: Getting Started However, when processing the compound expression, just before evaluating the "is equal to" Boolean operator, the NetScaler appliance promotes the character set of the value returned by HTTP.REQ.HEADER("MyHeader") to UTF-8. The first simple expression in the following example evaluates data in the ASCII character set. However, when the NetScaler appliance processes the compound expression, just before concatenating the results of the two simple expressions, the appliance promotes the character set of the value returned by HTTP.REQ.BODY(10) to UTF-8. HTTP.REQ.BODY(10) + HTTP.REQ.HEADER("MyHeader").SET_CHAR_SET(UTF_8) Consequently, the compound expression returns data in the UTF-8 character set.
Citrix NetScaler Policy Configuration and Reference Guide because "c8" cannot be followed by "20" (each byte in a multi-byte UTF-8 string must have the high bit set). Another example of an invalid UTF-8 character is "\xce \xa9," since the hexadecimal characters are separated by a white-space character.
Chapter 3
Configuring Default Syntax Expressions: Getting Started Note that when you upgrade the NetScaler to version 9.0 or higher, Integrated Caching policies are automatically upgraded to default syntax policies, and the expressions in these policies are upgraded to the default syntax. The following is the syntax for all default syntax expressions that use a classic expression: SYS.EVAL_CLASSIC_EXPR("expression") Following are examples of the SYS.EVAL_CLASSIC_EXPR("expression") expression: sys.eval_classic_expr("req.ssl.client.cipher.bits > 1000") sys.eval_classic_expr("url contains abc") sys.eval_classic_expr("req.ip.sourceip == 10.102.1.61 -netmask 255.255.255.255") sys.eval_classic_expr("time >= *:30:00GMT") sys.eval_classic_expr("e1 || e2") sys.eval_classic_expr("req.http.urllen > 50") sys.eval_classic_expr("dayofweek == wedGMT")
100
Citrix NetScaler Policy Configuration and Reference Guide q~http.req.url.contains("sometext") && http.req.cookie.exists~ Note that an expression that uses the { delimiter is closed with }. For some features (for example, Integrated Caching and Responder), the policy configuration dialog box provides a secondary dialog box for configuring expressions. This dialog enables you to choose from drop-down lists that show the available choices at each point during expression configuration. You cannot use arithmetic operators when using these configuration dialogs, but most other default syntax expression features are available. To use arithmetic operators , write your expressions in freeform format.
101
Chapter 3
Configuring Default Syntax Expressions: Getting Started 3. For most features, click in the Expression field. For Content Switching, click Configure. 4. Click the Prefix icon (the house) and select the first expression prefix from the dropdown list. For example, in Responder, the options are HTTP, SYS, and CLIENT. The next set of applicable options appear in a drop-down list. 5. Double-click the next option to select it, and then type a period (.). Again, a set of applicable options appears in another drop-down list. 6. Continue selecting options until an entry field (signalled by parentheses) appears. When you see an entry field, enter an appropriate value in the parentheses. For example, if you select GT(int) (greater-than, integer format), you specify an integer in the parentheses. Text strings are delimited by quotation marks. Following is an example: HTTP.REQ.BODY(1000).BETWEEN("this","that") 7. To insert an operator between two parts of a compound expression, click the Operators icon (the sigma), and select the operator type. Following is an example of a configured expression with a Boolean OR (signalled by double vertical bars, ||): HTTP.REQ.URL.EQ("www.mycompany.com")|| HTTP.REQ.BODY(1000).BETWEEN("this","that") 8. To insert a named expression, click the down arrow next to the Add icon (the plus sign) and select a named expression. 9. To configure an expression using drop-down menus, and to insert built-in expressions, click the Add icon (the plus sign). The Add Expression dialog box works in a similar way to the main dialog box, but it provides drop-down lists for selecting options, and it provides text fields for data entry instead of parentheses. This dialog box also provides a Frequently Used Expressions drop-down list that inserts commonly used expressions. When you are done adding the expression, click OK. 10. When finished, click Create. A message in the status bar indicates that the policy expression is configured successfully.
102
Citrix NetScaler Policy Configuration and Reference Guide 5. In the HTTP Request Data or HTTP Response Data field, paste the HTTP request or response that you want to parse with the expression, and click Evaluate. Note that you must supply a complete HTTP request or response, and the header and body should be separated by blank line. Some programs that trap HTTP headers do not also trap the response. If you are copying and pasting only the header, insert a blank line at the end of the header to form a complete HTTP request or response. 6. Click Close to close this dialog box.
103
Chapter 3
Configuring Default Syntax Expressions: Getting Started add rewrite action insert_b64encoded_authorization insert_http_header authorization '"Basic " + basic_header_value.b64encode' -bypassSafetyCheck YES In the example, in the expression that is used to construct the value of the custom header, the B64 encoding algorithm is applied to the string returned by the compound named expression. You can also use a named expression (either by itself or as a prefix to a function) to create the text expression for the replacement target in a rewrite.
To configure a named default syntax expression by using the NetScaler command line
At the NetScaler command prompt, type the following commands to configure a named expression and verify the configuration: w add policy expression expressionName rule w show policy expression expressionName Example > add policy expression myExp "http.req.body(100).contains(\"the other\")" Done > show policy expression myExp 1) Name: myExp Expr: "http.req.body(100).contains("the other")" Hits: 0 Type : ADVANCED Done The expression can be up to 1,499 characters.
104
To configure a default syntax expression outside a policy by using the NetScaler command line (cache selector example)
At the NetScaler command prompt, type the following commands to configure a default syntax expression outside a policy and verify the configuration: w add cache selector <selectorName> <expressions> w show cache selector <selectorName> Example > add cache selector mainpageSelector "http.req.cookie.value(\"ABC_def\")" "http.req.url.query.value(\"_ghi\")" selector "mainpageSelector" added Done > show cache selector mainpageSelector Name: mainpageSelector Expressions: 1) http.req.cookie.value("ABC_def") 2) http.req.url.query.value("_ghi") Done 105
Chapter 3
Configuring Default Syntax Expressions: Getting Started Following is an equivalent command that uses the more readable q delimiter, as described in Configuring Default Syntax Expressions in a Policy on page 100: > add cache selector mainpageSelector2 q~http.req.cookie.value("ABC_def")~ q~http.req.url.query.value("_ghi")~ selector "mainpageSelector2" added Done > show cache selector mainpageSelector2 Name: mainpageSelector2 Expressions: 1) http.req.cookie.value("ABC_def") 2) http.req.url.query.value("_ghi") Done
106
Chapter 4
107
Chapter 4
Note: Complex operations are available to perform matching based on patterns or to convert one type of text format to another type. For more information, see the following topics: w "Pattern Sets". w Regular Expressions on page 293. w Typecasting Data on page 277.
109
Chapter 4
Note: Parsing a document body, such as the body of a POST request, can affect performance. You may want to test the performance impact of policies that evaluate a document body.
Citrix NetScaler Policy Configuration and Reference Guide The following table describes the expression prefixes that you can configure to extract text from different parts of an HTTP request or response Table 4-1. HTTP Expression Prefixes That Return Text Prefix HTTP.REQ.BODY(<integer>) Description Returns the body of an HTTP request as a multiline text object, up to the character position designated in <integer>. There is no maximum value for the body argument, but you should use as small a value as is practical. Larger values can affect performance. Note: Although it is possible to specify this prefix without an integer argument, this usage is deprecated. HTTP.REQ.HOSTNAME Returns the HTTP host name in the first line of the request, if there is one. Otherwise, this prefix returns the value in the last occurrence of the HOST header. Note that there are two similar prefixes that return host names, as follows: w http.req.url.hostname only returns the host name from the URL w http.req.header("Host") only returns the value from the Host header. To use this value as a host name you must typecast this string, as illustrated in the following example: http.req.header("host").type cast_http_hostname_t For more information on typecasting, see Typecasting Data on page 277. HTTP.REQ.HOSTNAME. DOMAIN Returns the domain name part of the host name. For example, if the host name is www.myhost.com or www.myhost.com:8080, the domain is myhost.com.
111
Chapter 4
Prefix
Description Returns incorrect results if the host name has an IP address. For information on expressions for IP addresses, see Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs on page 249. All text operations that you specify after this prefix are case insensitive.
HTTP.REQ.HOSTNAME. SERVER
Returns the server name part of the host name. If the host name is www.myhost.com or www.myhost.com:8080, the server is www.myhost.com. All text operations that you specify after this prefix are case insensitive.
HTTP.REQ.METHOD
Returns the value of the METHOD in an HTTP request, or matches the method type if you provide it as an argument, for example, http.req.method.eq(get). If you enclose the argument in quotes, evaluation is case sensitive. Returns the HTTP URL. Returns the host name in the HTTP URL. Do not use this prefix in bidirectional policies. Note that there are two similar prefixes that return host names, as follows: w HTTP.REQ.HOSTNAME returns the host name from the URL if there is one; otherwise, it returns the value in the last occurrence of the Host header. w HTTP.REQ.HEADER("Host") only returns the value from the Host header. To use this value as a host name you must typecast this string, as illustrated in the following
HTTP.REQ.URL HTTP.REQ.URL.HOSTNAME
112
Prefix
Description example: http.req.header("host").type cast_http_hostname_t For more information on typecasting, see Typecasting Data on page 277.
HTTP.REQ.URL.HOSTNAME.DOMAIN
Returns the domain name part of the host name. For example, if the host name is www.myhost.com or www.myhost.com:8080, the domain is myhost.com. This operation returns incorrect results if the host name has an IP address. For information on expressions for IP addresses, see Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs on page 249. All text operations that you specify after this prefix are case insensitive unless explicitly set by the SET_TEXT_MODE operator.
HTTP.REQ.URL.HOSTNAME.SERVER
Returns the server name part of the host name. For example, if the host name is www.myhost.com or www.myhost.com: 8080, the server is www.myhost.com. All text operations that you specify after this prefix are case insensitive.
HTTP.REQ.URL.PATH
Returns a slash- (/) separated list from the path in a URL. For example, if the URL is http:// www.myhost.com/a/b/c/mypage.html? a=1, this prefix returns the string /a/b/c/ mypage.html. The expression http.req.url.path.get(1) returns "a" from the preceding URL. For more information on the GET operation, see Expressions for Extracting Segments of URLs on page 206.
113
Chapter 4
Prefix HTTP.REQ.URL.PATH_AND_QUERY
Description Returns the portion of the URL that follows the host name. For example, if the URL is http:// www.myhost.com/a/b/c/mypage.html? a=1, this prefix returns /a/b/c/ mypage.html?a=1.
HTTP.REQ.URL.PROTOCOL
Returns the protocol in the URL. This prefix cannot be used in bidirectional policies. Following is an example: http.req.hostname + http.req.url.protocol
HTTP.REQ.URL.QUERY
Returns a name-value list, using the delimiters = and & from the query component in the URL. Following is an example: http.req.url.query.contains("v iewReport && my_pagelabel")
HTTP.REQ.URL.QUERY.VALUE
Returns the value from the name-value pair in the argument supplied to this prefix, using the delimiter = from the query component in the URL. Following is an example: http.req.url.query.value("acti on") The first component that matches the name is selected. The matching process honors the IGNORECASE and the NOIGNORECASE text modes. The URLENCODED and the NOURLENCODED text modes are ignored.
HTTP.REQ.URL.SUFFIX
Returns the file name suffix in a URL. For example, if the path in the URL is /a/ b/c/mypage.html, this suffix selects html. Following is another example:
114
Prefix
HTTP.REQ.USER.NAME
Returns the name of the user in the request. Following is an example: http.req.username.contains("ro hit")
HTTP.REQ.VERSION
Returns the HTTP version listed in the request. Following is an example: http.req.version "\"HTTP/1.0\"
HTTP.RES.BODY(<integer>)
Returns a portion of the HTTP response body. The length of the returned text is equal to the number in the <integer> argument. If there are fewer characters in the body than are specified in <integer>, the entire body is returned. Following is an example: http.res.body(100).suffix('L', 1)
HTTP.RES.STATUS_MSG
Returns the HTTP response status message. Returns the HTTP version listed in the response. Returns a Boolean TRUE value if the host name matches the <hostname> argument. The comparison is case insensitive and if textmode is URLENCODED, the host name is decoded before comparison. For example, if the host name is www.mycompany.com., the following is true:
HTTP.RES.VERSION
HTTP.REQ.URL.HOSTNAME.EQ(<host name>)
115
Chapter 4
Prefix
HTTP.REQ.URL.HOSTNAME.PORT
Returns the port in the host name. The string following and including the first colon (:) is considered the port value. For example, if the host name is www.mycompany.com:8080, the port is ": 8080". If the host name is www.mycompany.com: the port is ":". If the host name is www.mycompany.com, the port is "" and points to a location just after ".com". If the numerical value in the port is missing, it assumes a default value of 80 or 443 (for HTTPS connections).
HTTP.REQ.URL.HOSTNAME.SERVER
Returns the server name portion of the host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the returned server name is www.mycompany.com. This method sets the text mode to case insensitive. All text operations after this method are case insensitive.
HTTP.REQ.URL.CVPN_ENCODE
Converts the URL to the clientless VPN format. Ignores the empty elements in the list. For example, if the element delimiter in the list is a comma, the following list has an empty element following a=10: a=10,b=11, ,c=89 The element following b=11 is not considered an empty element. As another example, consider the following header: Cust_Header : 123,,24, ,15
HTTP.REQ.URL.PATH.IGNORE_EMPTY _ELEMENTS
116
Prefix
Description The following expression returns a value of 4: http.req.header("Cust_Header") .typecast_list_t(',').ignore_e mpty_elements.count The following expression returns a value of 5: http.req.header("Cust_Header") .typecast_list_t(','). count
HTTP.REQ.URL.QUERY.IGNORE_EMPT Y_ELEMENTS
This method ignores the empty elements in a name-value list. For example, if the list delimiter is a semicolon, the following list has an empty element following a=10: a=10;;b=11; ;c=89 The element following b=11 is not considered an empty element. For example, consider the following header: Cust_Header : a=1;;b=2; ;c=3 The following expression returns a value of 4: http.req.header("Cust_Header") .typecast_nvlist_t('=',';').ig nore_empty_elements.count The following expression returns a value of 5: http.req.header("Cust_Header") .typecast_nvlist_t('=',';'). count
Table 4-2. HTTP Expression Prefixes That Return Text Prefix HTTP.REQ.BODY(<integer>) Description Returns the body of an HTTP request as a multiline text object, up to the
117
Chapter 4
Prefix
Description character position designated in <integer>. There is no maximum value for the body argument, but you should use as small a value as is practical. Larger values can affect performance. Note: Although it is possible to specify this prefix without an integer argument, this usage is deprecated.
HTTP.REQ.HOSTNAME
Returns the HTTP host name in the first line of the request, if there is one. Otherwise, this prefix returns the value in the last occurrence of the HOST header. Note that there are two similar prefixes that return host names, as follows: w http.req.url.hostname only returns the host name from the URL w http.req.header("Host") only returns the value from the Host header. To use this value as a host name you must typecast this string, as illustrated in the following example: http.req.header("host").type cast_http_hostname_t For more information on typecasting, see Typecasting Data on page 277
HTTP.REQ.HOSTNAME. DOMAIN
Returns the domain name part of the host name. For example, if the host name is www.myhost.com or www.myhost.com:8080, the domain is myhost.com. Returns incorrect results if the host name has an IP address. For information on expressions for IP addresses, see Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs on page 249.
118
Prefix
Description All text operations that you specify after this prefix are case insensitive.
HTTP.REQ.HOSTNAME. SERVER
Returns the server name part of the host name. If the host name is www.myhost.com or www.myhost.com: 8080, the server is www.myhost.com. All text operations that you specify after this prefix are case insensitive.
HTTP.REQ.METHOD
Returns the value of the METHOD in an HTTP request, or matches the method type if you provide it as an argument, for example, http.req.method.eq(get). If you enclose the argument in quotes, evaluation is case sensitive. Returns the HTTP URL. Returns the host name in the HTTP URL. Do not use this prefix in bidirectional policies. Note that there are two similar prefixes that return host names, as follows: w HTTP.REQ.HOSTNAME returns the host name from the URL if there is one; otherwise, it returns the value in the last occurrence of the Host header. w HTTP.REQ.HEADER("Host") only returns the value from the Host header. To use this value as a host name you must typecast this string, as illustrated in the following example: http.req.header("host").type cast_http_hostname_t For more information on typecasting, see Typecasting Data on page 277
HTTP.REQ.URL HTTP.REQ.URL.HOSTNAME
119
Chapter 4
Prefix HTTP.REQ.URL.HOSTNAME.DOMAIN
Description Returns the domain name part of the host name. For example, if the host name is www.myhost.com or www.myhost.com:8080, the domain is myhost.com. This operation returns incorrect results if the host name has an IP address. For information on expressions for IP addresses, see Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs on page 249. All text operations that you specify after this prefix are case insensitive unless explicitly set by the SET_TEXT_MODE operator.
HTTP.REQ.URL.HOSTNAME.SERVER
Returns the server name part of the host name. For example, if the host name is www.myhost.com or www.myhost.com: 8080, the server is www.myhost.com. All text operations that you specify after this prefix are case insensitive.
HTTP.REQ.URL.PATH
Returns a slash- (/) separated list from the path in a URL. For example, if the URL is http:// www.myhost.com/a/b/c/mypage.html? a=1, this prefix returns the string /a/b/c/ mypage.html. The expression http.req.url.path.get(1) returns "a" from the preceding URL. For more information on the GET operation, see Expressions for Extracting Segments of URLs on page 206.
HTTP.REQ.URL.PATH_AND_QUERY
Returns the portion of the URL that follows the host name. For example, if the URL is http:// www.myhost.com/a/b/c/mypage.html? a=1, this prefix returns /a/b/c/ mypage.html?a=1.
120
Prefix HTTP.REQ.URL.PROTOCOL
Description Returns the protocol in the URL. This prefix cannot be used in bidirectional policies. Following is an example: http.req.hostname + http.req.url.protocol
HTTP.REQ.URL.QUERY
Returns a name-value list, using the delimiters = and & from the query component in the URL. Following is an example: http.req.url.query.contains("v iewReport && my_pagelabel")
HTTP.REQ.URL.QUERY.VALUE
Returns the value from the name-value pair in the argument supplied to this prefix, using the delimiter = from the query component in the URL. Following is an example: http.req.url.query.value("acti on") The first component that matches the name is selected. The matching process honors the IGNORECASE and the NOIGNORECASE text modes. The URLENCODED and the NOURLENCODED text modes are ignored.
HTTP.REQ.URL.SUFFIX
Returns the file name suffix in a URL. For example, if the path in the URL is /a/ b/c/mypage.html, this suffix selects html. Following is another example: http.req.url.suffix.contains(" jpeg")
HTTP.REQ.USER
Returns the AAA user associated with the current HTTP transaction.
121
Chapter 4
Prefix HTTP.REQ.USER.EXTERNAL_GROUPS
Description Returns a list of the external groups to which a user belongs. The groups are separated by a comma (","). For example, HTTP.REQ.USER.EXTERNAL_GROUPS returns a comma-separated list of all the external groups to which the user belongs.
HTTP.REQ.USER.EXTERNAL_GROUPS. IGNORE_EMPTY_ELEMENTS
Ignores the empty elements in the list of external groups to which the user belongs. If the element delimiter in the list is a comma (","), then the following list has an empty element following "a=10": a=10,,b=11, ,c=89 But the element following "b=11" is not considered an empty element. For example, consider the following header in an HTTP request packet: Cust_Header : 123,,24, ,15 Then the following expression returns a value of 4: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(','). IGNORE_EMPTY_ELEMENTS.COUNT The following expression returns a value of 5: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(',').COUNT.
HTTP.REQ.USER.EXTERNAL_GROUPS( sep)
Returns a list of all the external groups to which the user belongs. The groups are separated by the given delimiter. For example, the following expression gives a list of all the external groups, and the groups are separated by a colon (":"): HTTP.REQ.USER.EXTERNAL_GROUPS( ':')
122
Prefix
HTTP.REQ.USER.EXTERNAL_GROUPS. IGNORE_EMPTY_ELEMENTS
Ignores the empty elements in the list of external groups to which the user belongs. If the element delimiter in the list is a comma (","), then the following list has an empty element following "a=10": a=10,,b=11, ,c=89 But the element following "b=11" is not considered an empty element. For example, consider the following header in an HTTP request packet: Cust_Header : 123,,24, ,15 The following expression returns a value of 4: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(','). IGNORE_EMPTY_ELEMENTS.COUNT The following expression returns a value of 5: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(',').COUNT
HTTP.REQ.USER.GROUPS
Returns a list of the internal and external groups to which the user belongs. The groups are separated by a comma (","). In this list, internal groups are listed first, followed by external groups.
HTTP.REQ.USER.GROUPS.IGNORE_EM PTY_ELEMENTS
Ignores the empty elements in the list of groups to which the user belongs. If the element delimiter in the list is a comma (","), then the following list has an empty element following "a=10": a=10,,b=11, ,c=89
123
Chapter 4
Prefix
Description But the element that follows "b=11" is not considered an empty element. For example, consider the following header in an HTTP request packet: Cust_Header : 123,,24, ,15 The following expression returns a value of 4: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(','). IGNORE_EMPTY_ELEMENTS.COUNT The following expression returns a value of 5: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(',').COUNT
HTTP.REQ.USER.GROUPS(sep)
Returns a list of groups to which the user belongs. The groups in the list are separated by the delimiter specified as the argument. For example, the following expression returns a colon-separated list of all the groups to which the user belongs. HTTP.REQ.USER.GROUPS(':') In this list, internal groups are listed first, followed by external groups. Parameters: sep - delimiter
HTTP.REQ.USER.GROUPS.IGNORE_EM PTY_ELEMENTS
Ignores the empty elements in the list of groups to which the user belongs. If the element delimiter in the list is a comma (","), then the following list has an empty element following "a=10": a=10,,b=11, ,c=89 But the element following "b=11" is not considered an empty element.
124
Prefix
Description For example, consider the following header in an HTTP request packet: Cust_Header : 123,,24, ,15 The following expression returns a value of 4: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(','). IGNORE_EMPTY_ELEMENTS.COUNT The following expression returns a value of 5: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(',').COUNT.
HTTP.REQ.USER.INTERNAL_GROUPS
Returns a list of internal groups to which the user belongs. The groups are separated by a comma (","). For example, the following expression returns a comma-separated list of all the internal groups to which a user belongs. HTTP.REQ.USER.INTERNAL_GROUPS
HTTP.REQ.USER.INTERNAL_GROUPS. IGNORE_EMPTY_ELEMENTS
Ignores the empty elements in the list of internal groups to which the user belongs. If the element delimiter in the list is a comma (","), then the following list has an empty element following "a=10": a=10,,b=11, ,c=89 But the element following "b=11" is not considered an empty element. For example, consider the following header in an HTTP request packet: Cust_Header : 123,,24, ,15 The following expression returns a value of 4: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(','). IGNORE_EMPTY_ELEMENTS.COUNT
125
Chapter 4
Prefix
HTTP.REQ.USER.INTERNAL_GROUPS( sep)
Returns a list of the internal groups to which the user belongs. The groups are separated by the given delimiter. For example, the following expression returns a colon-separated list of all the internal groups to which the user belongs. HTTP.REQ.USER.INTERNAL_GROUPS( ':') Parameters: sep - delimiter
HTTP.REQ.USER.INTERNAL_GROUPS. IGNORE_EMPTY_ELEMENTS
Ignores the empty elements in the list of internal groups to which the user belongs. If the element delimiter in the list is a comma (","), then the following list has an empty element following "a=10": a=10,,b=11, ,c=89 But the element following "b=11" is not considered an empty element. For example, consider the following header in an HTTP request packet: Cust_Header : 123,,24, ,15 The following expression returns a value of 4: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(','). IGNORE_EMPTY_ELEMENTS.COUNT The following expression returns a value of 5: HTTP.REQ.HEADER("Cust_Header") .TYPECAST_LIST_T(',').COUNT.
126
Description Returns a boolean TRUE if the user who is named in the request is a member of the argument specified in group. Following is an example: http.req.user.is_member_of("my group") Parameter: group_name: The name of the group.
HTTP.REQ.USER.NAME
Returns the name of the user in the request. Following is an example: http.req.username.contains("ro hit")
HTTP.REQ.USER.PASSWD HTTP.REQ.VERSION
Returns the password of the user. Returns the HTTP version listed in the request. Following is an example: http.req.version "\"HTTP/1.0\"
HTTP.RES.BODY(<integer>)
Returns a portion of the HTTP response body. The length of the returned text is equal to the number in the <integer> argument. If there are fewer characters in the body than are specified in <integer>, the entire body is returned. Following is an example: http.res.body(100).suffix('L', 1)
HTTP.RES.STATUS_MSG
Returns the HTTP response status message. Returns the HTTP version listed in the response.
HTTP.RES.VERSION
127
Chapter 4
Description Returns a Boolean TRUE value if the host name matches the <hostname> argument. The comparison is case insensitive and if textmode is URLENCODED, the host name is decoded before comparison. For example, if the host name is www.mycompany.com., the following is true: http.req.url.hostname.eq("www. mycompany.com")
HTTP.REQ.URL.HOSTNAME.PORT
Returns the port in the host name. The string following and including the first colon (:) is considered the port value. For example, if the host name is www.mycompany.com:8080, the port is ": 8080". If the host name is www.mycompany.com: the port is ":". If the host name is www.mycompany.com, the port is "" and points to a location just after ".com". If the numerical value in the port is missing, it assumes a default value of 80 or 443 (for HTTPS connections).
HTTP.REQ.URL.HOSTNAME.SERVER
Returns the server name portion of the host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the returned server name is www.mycompany.com. This method sets the text mode to case insensitive. All text operations after this method are case insensitive.
HTTP.REQ.IS_NTLM_OR_NEGOTIATE
Returns a Boolean TRUE if the request is a part of an NTLM or NEGOTIATE connection. Converts the URL to the clientless VPN format.
HTTP.REQ.URL.CVPN_ENCODE
128
Description Ignores the empty elements in the list. For example, if the element delimiter in the list is a comma, the following list has an empty element following a=10: a=10,b=11, ,c=89 The element following b=11 is not considered an empty element. As another example, consider the following header: Cust_Header : 123,,24, ,15 The following expression returns a value of 4: http.req.header("Cust_Header") .typecast_list_t(',').ignore_e mpty_elements.count The following expression returns a value of 5: http.req.header("Cust_Header") .typecast_list_t(','). count
HTTP.REQ.URL.QUERY.IGNORE_EMPT Y_ELEMENTS
This method ignores the empty elements in a name-value list. For example, if the list delimiter is a semicolon, the following list has an empty element following a=10: a=10;;b=11; ;c=89 The element following b=11 is not considered an empty element. For example, consider the following header: Cust_Header : a=1;;b=2; ;c=3 The following expression returns a value of 4: http.req.header("Cust_Header") .typecast_nvlist_t('=',';').ig nore_empty_elements.count
129
Chapter 4
Prefix
VPN.BASEURL.CVPN_ENCODE VPN.BASEURL.HOSTNAME
130
Description For example, if the host name is www.mycompany.com or www.mycompany.com:8080, this prefix extracts mycompany.com. This prefix returns incorrect results if the host name is an IP address. For information on expressions for IP addresses, see Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs on page 249. All text operations after this prefix are case insensitive.
VPN.BASEURL.HOSTNAME.EQ (<hostname>)
Returns a Boolean TRUE if the host name matches <hostname>. The comparison is case insensitive. For example, if the host name is www.mycompany.com, the following returns TRUE: vpn.baseurl.hostname.eq("www.m ycompany.com") If the text mode is URLENCODED, the host name is decoded before comparison. For more information, see Operations for HTTP, HTML, and XML Encoding and Safe Characters on page 221.
VPN.BASEURL.HOSTNAME.SERVER
Evaluates the server portion of the host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the server is www.mycompany.com. All text operations after this prefix are case insensitive.
VPN.BASEURL.PATH
Extracts a slash- (/) separated list from the path component of the URL. For example, this prefix extracts /a/b/c/ mypage.html from the following URL:
131
Chapter 4
Description http://www.mycompany.com/a/b/c/ mypage.html?a=1 The following expression selects just the a: http.req.url.path.get(1) For more information on the GET operation, see Expressions for Extracting Segments of URLs on page 206.
VPN.BASEURL.PATH.IGNORE_EMPTY_ ELEMENTS
This prefix ignores the elements in a list. For example, the following commaseparated list has an empty element after a=10: a=10,,b=11, ,c=89 The element following b=11 contains a space, and by default, is not considered an empty element. Consider the following HTTP header: Cust_Header : 123,,24, ,15 The following expression returns a count of 4 when evaluating this header: http.req.header("Cust_Header") .typecase_list_t(',').ignore_e mpty_elements.count The following expression returns a count of 5 when evaluating this header: http.req.header("Cust_Header") .typecase_list_t(','). count
VPN.BASEURL.PATH_AND_QUERY
Evaluates the text in the URL that follows the host name. For example, if the URL is http:// www.mycompany.com/a/b/c/ mypage.html?a=1, this prefix evaluates / a/b/c/mypage.html?a=1.
VPN.BASEURL.PROTOCOL
132
VPN.BASEURL.QUERY
Extracts a name-value list, using the = and & delimiters from the query string in a URL. This method ignores the empty elements in a name-value list. For example, in the following name-value list, there is an empty element following a=10: a=10;;b=11; ;c=89 The element following b=11 contains a space and is not considered an empty element. Consider the following HTTP header: Cust_Header : a=1;;b=2; ;c=3 The following expression produces a count of 4 after evaluating this header: http.req.header("Cust_Header") .typecast_nvlist_t('=',';').ig nore_empty_elements.count The following expression produces a count of 5 after evaluating the header: http.req.header("Cust_Header") .typecast_nvlist_t('=',';').
VPN.BASEURL.QUERY.IGNORE_EMPTY _ELEMENTS
VPN.BASEURL.SUFFIX
Evaluates the file name suffix in a URL. For example, if the path is /a/b/c/ my.page.html, this operation selects html.
Evaluates the clientless VPN base URL. Extracts the original URL from the clientless VPN formatted URL. Converts a URL to the clientless VPN format.
133
Chapter 4
Description Evaluates the host name in the URL. Do not use this prefix in bidirectional policies. Evaluates the domain name part of the host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the domain is mycompany.com. This operation returns incorrect results if the host name is an IP address. For information on expressions for IP addresses, see Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs on page 249. All text operations after this prefix are case insensitive.
VPN.CLIENTLESS_BASEURL.HOSTNAM E.DOMAIN
VPN.CLIENTLESS_BASEURL.HOSTNAM E.EQ(<hostname>)
Returns a Boolean TRUE if the host name matches <hostname>. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the following is true: vpn.clientless_baseurl. hostname.eq("www.mycompany.com ") The comparison is case insensitive. If the textmode is URLENCODED, the host name is decoded before comparison. For more information, see Operations for HTTP, HTML, and XML Encoding and Safe Characters on page 221.
VPN.CLIENTLESS_BASEURL.HOSTNAM E.SERVER
Evaluates the server part of a host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the server is www.mycompany.com.
134
Description All text operations after this prefix are case insensitive.
VPN.CLIENTLESS_BASEURL.PATH
Evaluates a slash- (/) separated list in the URL path. For example, this prefix selects /a/b/c/ mypage.html from the following URL: http://www.mycompany.com/a/b/c/ mypage.html?a=1 The following expression selects a from the preceding URL: http.req.url.path.get(1) For more information on the GET operation, see Expressions for Extracting Segments of URLs on page 206.
VPN.CLIENTLESS_BASEURL.PATH.IG NORE_EMPTY_ELEMENTS
Ignores empty elements in a list. For example, if the list delimiter is a comma (,) the following list has an empty element following a=10: a=10,b=11, ,c=89 The element following b=11 contains a space and is not considered an empty element. Consider the following HTTP header: Cust_Header : 123,,24, ,15 The following expression returns a value of 4 after evaluating this header: http.req.header("Cust_Header") .typecast_list_t(',').ignore_e mpty_elements.count The following expression returns a value of 5 after evaluating this header: http.req.header("Cust_Header") .typecast_list_t(',').
135
Chapter 4
Description Evaluates the text following the host name in a URL. For example, this prefix selects /a/b/c/ mypage.html?a=1 from the following URL: http://www.mycompany.com/a/b/c/ mypage.html?a=1
VPN.CLIENTLESS_BASEURL.PROTOCO L
Evaluates the protocol in the URL. Do not use this prefix in bidirectional policies. Extracts a name-value list that uses the delimiters = and & from a URL query string. Ignores empty elements in a name-value list. For example, the following list contains an empty element after a=10: a=10;;b=11; ;c=89 The element following b=11 contains a space and is not considered an empty element. As another example, consider the following http header: Cust_Header : a=1;;b=2; ;c=3 The following expression returns a value of 4 after evaluating the preceding header: http.req.header("Cust_Header") .typecast_nvlist_t('=',';').ig nore_empty_elements.count The following expression returns a value of 5 after evaluating the preceding header: http.req.header("Cust_Header") .typecast_nvlist_t('=',';')
VPN.CLIENTLESS_BASEURL.QUERY
136
Description Evaluates the file suffix in a URL. For example, if the URL path is /a/b/c/ mypage.html then this operation selects html. Selects the clientless VPN host URL. Selects the original URL from the clientless VPN formatted URL. Converts a URL to clientless VPN format.
Extracts the host name in the URL. Do not use this prefix in bidirectional policies. Extracts the domain name from the host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the domain is mycompany.com. This operation returns incorrect results if the host name contains an IP address. For information on expressions for IP addresses, see Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs on page 249. All text operations after this prefix are case insensitive.
VPN.CLIENTLESS_HOSTURL.HOSTNAM E.DOMAIN
VPN.CLIENTLESS_HOSTURL.HOSTNAM E.EQ(<hostname>)
Results in Boolean TRUE if the host name matches the <hostname> argument. The comparison is case insensitive. For example, if the host name is www.mycompany.com or www.mycompany.com., the following expression returns TRUE: vpn.clilentless_hosturl. hostname.eq("www.mycompany.com ")
137
Chapter 4
Description If the text mode is URLENCODED, the host name is decoded before comparison. For more information, see Operations for HTTP, HTML, and XML Encoding and Safe Characters on page 221.
VPN.CLIENTLESS_HOSTURL.HOSTNAM E.SERVER
Evaluates the server part of the host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the server is www.mycompany.com. The comparison is case insensitive, and all text operations after this method are case insensitive.
VPN.CLIENTLESS_HOSTURL.PATH
Evaluates a slash- (/) separated list on the path component of the URL. For example, consider the following URL: http://www.mycompany.com/a/b/c/ mypage.html?a=1 This prefix selects /a/b/c/mypage.html from the preceding URL.
VPN.CLIENTLESS_HOSTURL.PATH.IG NORE_EMPTY_ELEMENTS
This method ignores the empty elements in a list. For example, if the delimiter in a list is , the following list contains an empty element after the entry a=10: a=10,b=11, ,c=89 The element following b=11 contains a space and is not considered an empty element. Consider the following header: Cust_Header : 123,,24, ,15 The following expression returns a value of 4 for this header:
138
Description http.req.header("Cust_Header") .typecast_list_t(','). ignore_empty_elements.count The following expression returns a value of 5 for the same header: http.req.header("Cust_Header") .typecast_list_t(',').
VPN.CLIENTLESS_HOSTURL.PATH_AN D_QUERY
Evaluates the portion of the URL that follows the host name. For example, consider the following URL: http://www.mycompany.com/a/b/c/ mypage.html?a=1 This prefix returns /a/b/c/mypage.html? a=1 from the preceding URL.
VPN.CLIENTLESS_HOSTURL.PROTOCO L
Evaluates the protocol in the URL. Do not use this prefix in bidirectional policies. Extracts a name-value list, using the = and & delimiters from a URL query string. Ignores empty elements in a name-value list. For example, the following list uses a semicolon (;) delimiter. This list contains an empty element after a=10: a=10;;b=11; ;c=89 In the preceding example, the element following b=11 is not considered an empty element. Consider the following header: Cust_Header : a=1;;b=2; ;c=3 The following expression returns a value of 4 after evaluating this header:
VPN.CLIENTLESS_HOSTURL.QUERY
139
Chapter 4
Description http.req.header("Cust_Header") .typecast_nvlist_t('=',';').ig nore_empty_elements.count The following expression returns a value of 5 after evaluating the same header: http.req.header("Cust_Header") .typecast_nvlist_t('=',';')
VPN.CLIENTLESS_HOSTURL.SUFFIX
Extracts a file name suffix in a URL. For example, if the path is /a/b/c/ my.page.html, this prefix selects html.
VPN.HOST.DOMAIN
Extracts the domain name part of the host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the domain is mycompany.com. This prefix returns incorrect results if the host name contains an IP address. For information on expressions for IP addresses, see Default Syntax Expressions: IP and MAC Addresses, Throughput, VLAN IDs on page 249. All text operations after this prefix case insensitive.
VPN.HOST.EQ(<hostname>)
Returns a Boolean TRUE value if the host name matches the <hostname>. The comparison is case insensitive. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the following returns TRUE: vpn.host.eq("www.mycompany.com ") If the text mode is URLENCODED the host name is decoded before comparison. For more information, see Operations for HTTP, HTML, and XML Encoding and Safe Characters on page 221.
140
Description Extracts the server name part of the host name. For example, if the host name is www.mycompany.com or www.mycompany.com:8080, the server is www.mycompany.com. All text operations after this prefix are case insensitive.
141
Chapter 4
Function
Description For example, the following expression returns a Boolean TRUE for a URL with a host name of myhostabc: http.req.url.hostname.startswi th("myhost")
<text>.ENDSWITH(<string>)
Returns a Boolean TRUE value if the target ends with <string>. For example, the following expression returns a Boolean TRUE for a URL with a host name of myhostabc: http.req.url.hostname.endswith ("abc")
<text>.NE(<string>)
Returns a Boolean TRUE value if the prefix is not equal to the string argument. If the prefix returns a non-string value, the function argument is compared to the string representation of the value returned by the prefix. You can use the functions with SET_TEXT_MODE(IGNORECASE) or SET_TEXT_MODE(NOIGNORECASE), and with both ASCII and UTF-8 character sets.
<text>.GT(<string>)
Returns a Boolean TRUE value if the prefix is alphabetically greater than the string argument. If the prefix returns a non-string value, the function argument is compared to the string representation of the value returned by the prefix. You can use the functions with SET_TEXT_MODE(IGNORECASE) or SET_TEXT_MODE(NOIGNORECASE), and with both ASCII and UTF-8 character sets.
<text>.GE(<string>)
Returns a Boolean TRUE value if the prefix is alphabetically greater than or equal to the string argument. If the prefix returns a non-string value, the function argument is compared to
142
Function
Description the string representation of the value returned by the prefix. You can use the functions with SET_TEXT_MODE(IGNORECASE) or SET_TEXT_MODE(NOIGNORECASE), and with both ASCII and UTF-8 character sets.
<text>.LT(<string>)
Returns a Boolean TRUE value if the prefix is alphabetically lesser than the string argument. If the prefix returns a non-string value, the function argument is compared to the string representation of the value returned by the prefix. You can use the functions with SET_TEXT_MODE(IGNORECASE) or SET_TEXT_MODE(NOIGNORECASE), and with both ASCII and UTF-8 character sets.
<text>.LE(<string>)
Returns a Boolean TRUE value if the prefix is alphabetically lesser than or equal to the string argument. If the prefix returns a non-string value, the function argument is compared to the string representation of the value returned by the prefix. You can use the functions with SET_TEXT_MODE(IGNORECASE) or SET_TEXT_MODE(NOIGNORECASE), and with both ASCII and UTF-8 character sets.
Chapter 4
Citrix NetScaler Policy Configuration and Reference Guide The following functions strip matching characters from the beginning and end of a given string input. Table 4-6. Functions for Stripping Characters From the Beginning or End of a String Function <text>.STRIP_START_CHARS(s) Description Strips matching characters from the beginning of the input string until the first non-matching character is found and returns the remainder of the string. You must specify the characters that you want to strip as a single string within quotation marks. For example, if the name of a header is TestLang and ://_en_us: is its value, HTTP.RES.HEADER("TestLang").ST RIP_START_CHARS(":/_") strips the specified characters from the beginning of the value of the header until the first non-matching character e is found and returns en_us: as a string. <text>.STRIP_END_CHARS(s) Strips matching characters from the end of the input string to the first nonmatching character is found and returns the remainder of the string. You must specify the characters that you want to strip as a single string within quotation marks. For example, if the name of a header is TestLang and ://_en_us: is its value, HTTP.RES.HEADER("TestLang").ST RIP_START_CHARS(":/_") strips the specified characters from the end of the value of the header until the first nonmatching character s is found and returns ://_en_us as a string.
Chapter 4
<text>.PREFIX(<character>, <count>)
146
Select a string with <length> number of characters from the target object. Begin extracting the string after the <starting_offset>. If the number of characters after the offset are fewer than the value of the <length> argument, select all the remaining characters. Select a string from the target after skipping over the longest prefix that has at most <count> occurrences of <character>.
<text>.SKIP(<character>, <count>)
147
Chapter 4
Description Returns the text that follows the first occurrence of <string>. If there is no match for <string>, the expression returns a text object of 0 length. Following is an example: http.res.body(1024).after_str( "start_string").before_str("en d_string").contains("https")
Returns a Boolean TRUE value if the length of the text object is greater than or equal to the sum <starting string>, <ending string> argument lengths, and if a prefix of the target matches <starting string>, and if the suffix of the target matches <ending string>. Returns the starting string from a target block of text that contains the number of characters in the <prefix length> argument. If the <prefix length> argument exceeds the number of characters in the target, the entire string is selected.
<text>.PREFIX(<prefix length>)
<text>.SUFFIX(<suffix length>)
Returns the ending string from a target block of text that contains the number of characters in the <suffix length> argument. If the <suffix length> argument exceeds the number characters in the target, the entire string is selected. Select the first block of text in the target that matches the <string>. Selects the text in the target after skipping over a <prefix length> number of characters.
<text>.SUBSTR(<string>)
<text>.SKIP(<prefix length>)
148
Description If the entire target has fewer characters than <prefix length>, the entire target is skipped.
<text>.STRIP_END_WS
Selects the text after removing white space from the end of the target. Selects the text after removing white space from the beginning of the target. Selects the <character>, removes white space that immediately precedes and follows the <character>, and if the remaining text is quoted by <character>, this prefix also removes the quotes. For example, the operation UNQUOTE('"') changes the following text: "abc xyz def " To the following: abc xyz def
<text>.STRIP_START_WS
<text>.UNQUOTE(<character>)
149
Chapter 4
<text>.GET_UNSIGNED8(<n>)
<text>.GET_SIGNED16(<n>, <endianness>)
150
Function
Description Note: In NetScaler 9.2, the parameter n was an index into an array of 16-bit items. In NetScaler 9.3, the parameter is a byte offset. Therefore, if you used this function in NetScaler 9.2, after you upgrade to NetScaler 9.3, you must change n to 2*n to obtain the same results as you did earlier. For example, if the value of n before the upgrade was 4, you must change the value of n to 8. The parameter endianness also no longer takes the values that it did in NetScaler 9.2, which were 0 and 1. Instead, endianness accepts the mnemonic values mentioned earlier. Example HTTP.REQ.BODY(100).GET_SIGNED1 6(8, BIG_ENDIAN)
<text>.GET_UNSIGNED16(<n>, <endianness>)
Treats the text string returned by the prefix as a string of bytes, extracts 16 bits starting at byte offset n, and converts the extracted bit sequence to a 16-bit unsigned integer. If the offset makes all or part of the value outside of the current text, an UNDEF condition is raised. The first parameter n is the byte offset from the current position in the text string. Providing a byte offset enables the function to handle items that are not aligned on the boundaries that are required by indexes. The second parameter, endianness, takes a mnemonic value of LITTLE_ENDIAN or BIG_ENDIAN. Note: In NetScaler 9.2, the parameter n was an index into an array of 16-bit items. In NetScaler 9.3, the parameter is a byte offset. Therefore, if you used this function in NetScaler 9.2, after you
151
Chapter 4
Function
Description upgrade to NetScaler 9.3, you must change n to 2*n to obtain the same results as you did earlier. For example, if the value of n before the upgrade was 4, you must change the value of n to 8. The parameter endianness also no longer takes the values that it did in NetScaler 9.2, which were 0 and 1. Instead, endianness accepts the mnemonic values mentioned earlier. Example HTTP.REQ.BODY(100).GET_UNSIGNE D16(8, LITTLE_ENDIAN)
<text>.GET_SIGNED32(<n>, <endianness>)
Treats the text string returned by the prefix as a string of bytes, extracts 32 bits starting at byte offset n, and converts the extracted bit sequence to a 32-bit signed integer. If the offset makes all or part of the value outside of the current text, an UNDEF condition is raised. The first parameter n is the byte offset from the current position in the text string. Providing a byte offset enables the function to handle items that are not aligned on the boundaries that are required by indexes. The second parameter, endianness, takes a mnemonic value of LITTLE_ENDIAN or BIG_ENDIAN. Note: In NetScaler 9.2, the parameter n was an index into an array of 32-bit items. In NetScaler 9.3, the parameter is a byte offset. Therefore, if you used this function in NetScaler 9.2, after you upgrade to NetScaler 9.3, you must change n to 4*n to obtain the same results as you did earlier. For example, if the value of n before the upgrade was 4, you must change the value of n to 16. The parameter endianness
152
Function
Description also no longer takes the values that it did in NetScaler 9.2, which were 0 and 1. Instead, endianness accepts the mnemonic values mentioned earlier. Example HTTP.REQ.BODY(1000).GET_SIGNED 32(12, BIG_ENDIAN)
<text>.GET_UNSIGNED32(<n>, <endianness>)
Treats the text string returned by the prefix as a string of bytes, extracts 32 bits starting at byte offset n, and returns the extracted bit sequence as part of a 64-bit unsigned long integer. If the offset makes all or part of the value outside of the current text, an UNDEF condition is raised. The first parameter n is the byte offset from the current position in the text string. Providing a byte offset enables the function to handle items that are not aligned on the boundaries that are required by indexes. The second parameter, endianness, takes a mnemonic value of LITTLE_ENDIAN or BIG_ENDIAN. Example HTTP.REQ.BODY(1000).GET_UNSIGN ED32(30, LITTLE_ENDIAN)
153
Chapter 4
text.B64DECODE
154
Citrix NetScaler Policy Configuration and Reference Guide Additionally, the EXTEND function can be used only with the following types of rewrite actions: w replace_all w insert_after_all w delete_all w insert_before_all For example, you might want to delete all instances of "http://exampleurl.com/" and "http://exampleurl.au/" in the first 1000 bytes of the body. To do this, you can configure a rewrite action to search for all instances of the string exampleurl, extend the scope of the search on both sides of the string when a match is found, and then use a regular expression to perform the rewrite in the extended region. The following example extends the scope of the search by 20 bytes to the left and 50 bytes to the right of the matching string: add rewrite action delurl_example delete_all 'HTTP.REQ.BODY(1000)' -pattern exampleurl -refineSearch 'extend(20,50).regex_select(re#http://exampleurl.(com|au)#)'
155
Chapter 4
Configuring Encryption
During startup, the appliance runs the set ns encryptionParams command with, by default, the AES256 encryption method, and uses a randomly generated key value that is appropriate for AES256 encryption. The appliance also encrypts the key value and saves the command, with the encrypted key value, to the NetScaler configuration file. Consequently, the AES256 encryption method is enabled for the ENCRYPT and DECRYPT functions by default. The key value that is saved in the configuration file persists across reboots even though the appliance runs the command each time you restart it. You can run the set ns encryptionParams command manually, or use the configuration utility, if you want to change the encryption method or if you want the appliance to generate a new key value for the current encryption method. To use the CLI to change the encryption method, set only the method parameter, as shown in "Example 1: Changing the Encryption Method." If you want the appliance to generate a new key value for the current encryption method, set the method parameter to the current encryption method and the keyValue parameter to an empty string (""), as shown in "Example 2: Generating a New Key Value for the Current Encryption Method." After you generate a new key value, you must save the configuration. If you do not save the configuration, the appliance uses the newly generated key value only until the next restart, after which it reverts to the key value in the saved configuration.
157
Chapter 4
158
Chapter 5
159
Chapter 5
161
Chapter 5
Description Returns the current day of the month as a number from 1 through 31. Returns a Boolean TRUE if the current time is equal to the <time> argument. For example, if the current time is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month, you can specify the following (evaluation results are shown in parentheses): w sys.time.eq(GMT 2005) (TRUE in this example.) w sys.time.eq(GMT 2005 Dec) (FALSE in this example.) w sys.time.eq(LOCAL 2005 May) (Evaluates to TRUE or FALSE in this example, depending on the current time zone.) w sys.time.eq(GMT 10h) (TRUE in this example.) w sys.time.eq(GMT 10h 30s) (TRUE in this example.) w sys.time.eq(GMT May 10h) (TRUE in this example.) w sys.time.eq(GMT Sun) (TRUE in this example.) w sys.time.eq(GMT May Sun_1) (TRUE in this example.)
SYS.TIME.EQ(<time>)
SYS.TIME.NE(<time>)
Returns a Boolean TRUE if the current time is not equal to the <time> argument. Returns a Boolean TRUE if the current time is later than or equal to <time>. For example, if the current time is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month, you can specify the following (evaluation results are shown in parentheses):
SYS.TIME.GE(<time>)
162
Description w sys.time.ge(GMT 2004) (TRUE in this example.) w sys.time.ge(GMT 2005 Jan) (TRUE in this example.) w sys.time.ge(LOCAL 2005 May) (TRUE or FALSE in this example, depending on the current time zone.) w sys.time.ge(GMT 8h) (TRUE in this example.) w sys.time.ge(GMT 30m) (FALSE in this example.) w sys.time.ge(GMT May 10h) (TRUE in this example.) w sys.time.ge(GMT May 10h 0m) (TRUE in this example.) w sys.time.ge(GMT Sun) (TRUE in this example.) w sys.time.ge(GMT May Sun_1) (TRUE in this example.)
SYS.TIME.GT(<time>)
Returns a Boolean TRUE if the time value is later than the <time> argument. For example, if the current time is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month, you can specify the following (evaluation results are shown in parentheses): w sys.time.gt(GMT 2004) (TRUE in this example.) w sys.time.gt(GMT 2005 Jan) (TRUE in this example.) w sys.time.gt(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone. ) w sys.time.gt(GMT 8h) (TRUE in this example.) w sys.time.gt(GMT 30m) (FALSE in this example.) 163
Chapter 5
Description w sys.time.gt(GMT May 10h) (FALSE in this example.) w sys.time.gt(GMT May 10h 0m) (TRUE in this example.) w sys.time.gt(GMT Sun) (FALSE in this example.) w sys.time.gt(GMT May Sun_1) (FALSE in this example.)
SYS.TIME.HOURS
Returns the current hour as an integer from 0 to 23. Returns a Boolean TRUE if the current time value precedes or is equal to the <time> argument. For example, if the current time is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month, you can specify the following (evaluation results are shown in parentheses): w sys.time.le(GMT 2006) (TRUE in this example.) w sys.time.le(GMT 2005 Dec) (TRUE in this example.) w sys.time.le(LOCAL 2005 May) (TRUE or FALSE depending on the current timezone. ) w sys.time.le(GMT 8h) (FALSE in this example.) w sys.time.le(GMT 30m) (TRUE in this example.) w sys.time.le(GMT May 10h) (TRUE in this example.) w sys.time.le(GMT Jun 11h) (TRUE in this example.) w sys.time.le(GMT Wed) (TRUE in this example.)
SYS.TIME.LE(<time>)
164
SYS.TIME.LT(<time>)
Returns a Boolean TRUE if the current time value precedes the <time> argument. For example, if the current time is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month, you can specify the following (evaluation results are shown in parentheses): w sys.time.lt(GMT 2006) (TRUE in this example.) w sys.time.lt.time.lt(GMT 2005 Dec) (TRUE in this example.) w sys.time.lt(LOCAL 2005 May) (TRUE or FALSE depending on the current time zone.) w sys.time.lt(GMT 8h) (FALSE in this example.) w sys.time.lt(GMT 30m) (TRUE in this example.) w sys.time.lt(GMT May 10h) (FALSE in this example.) w sys.time.lt(GMT Jun 11h) (TRUE in this example.) w sys.time.lt(GMT Wed) (TRUE in this example.) w sys.time.lt(GMT May Sun_1) (FALSE in this example.)
SYS.TIME.MINUTES
Returns the current minute as an integer from 0 to 59. Extracts the current month and returns an integer from 1 (January) to 12 (December).
SYS.TIME.MONTH
165
Chapter 5
Description Calculates the number of seconds to the closest previous or scheduled reboot, and returns an integer. If the closest boot time is in the past, the integer is negative. If it is in the future, the integer is positive.
SYS.TIME.RELATIVE_NOW
Calculates the number of seconds between the current NetScaler system time and the specified time, and returns an integer showing the difference. If the designated time is in the past, the integer is negative; if it is in the future, the integer is positive.
SYS.TIME.SECONDS
Extracts the seconds from the current NetScaler system time, and returns that value as an integer from 0 to 59. Returns the current weekday as a value from 0 (Sunday) to 6 (Saturday). If you omit an element of time in <time1>, for example, the day or hour, it is assumed to have the lowest value in its range. If you omit an element in <time2>, it is assumed to have the highest value of its range. The ranges for the elements of time are as follows: month 1-12, day 1-31, weekday 0-6, hour 0-23, minutes 0-59 and seconds 0-59. If you specify the year, you must do so in both <time1> and <time2>. For example, if the time is GMT 2005 May 10 10h 15m 30s, and it is the second Tuesday of the month, you can specify the following (evaluation results are shown in parentheses): w sys.time.within(GMT 2004, GMT 2006) (TRUE in this example.)
SYS.TIME.WEEKDAY
166
Description w sys.time.within(GMT 2004 Jan, GMT 2006 Mar) (FALSE, May is not in the range of January to March.) w sys.time.within(GMT Feb, GMT) (TRUE, May is in the range of February to December.) w sys.time.within(GMT Sun_1, GMT Sun_3) (TRUE, the second Tuesday is between the first Sunday and the third Sunday.) w sys.time.within(GMT 2005 May 1 10h, GMT May 2005 1 17h) (TRUE in this example.) w sys.time.within(LOCAL 2005 May 1, LOCAL May 2005 1) (TRUE or FALSE, depending on the NetScaler system time zone.)
SYS.TIME.YEAR
Extracts the year from the current system time and returns that value as a four-digit integer.
167
Chapter 5
Default Syntax Expressions: Working with Dates, Times, and Numbers Table 5-2. Operations on Certificate (client.ssl.client_cert) Dates and Times SSL Certificate Operation <certificate>.VALID_NOT_AFTER Description Returns the last day before certificate expiration. The return format is the number of seconds since GMT January 1, 1970 (0 hours, 0 minutes, 0 seconds). Returns a Boolean TRUE value if the certificate validity is between the <time1> and <time2> arguments. Both <time1> and <time2> must be fully specified. Following are examples: GMT 1995 Jan is fully specified. GMT Jan is not fully specified GMT 1995 20 is not fully specified. GMT Jan Mon_2 is not fully specified. The <time1> and <time2> arguments must be both GMT or both LOCAL, and <time2> must be greater than <time1>. For example, if it is GMT 2005 May 1 10h 15m 30s, and the first Sunday of the month, you can specify the following (evaluation results are in parentheses). w . . .between(GMT 2004, GMT 2006) (TRUE) w . . .between(GMT 2004 Jan, GMT 2006 Nov) (TRUE) w . . .between(GMT 2004 Jan, GMT 2006) (TRUE) w . . .between(GMT 2005 May Sun_1, GMT 2005 May Sun_3) (TRUE) w . . .between(GMT 2005 May 1, GMT May 2005 1) (TRUE) w . . .between(LOCAL 2005 May 1, LOCAL May 2005 1) (TRUE or FALSE, depending on the NetScaler system time zone.)
168
Description Extracts the last day of the month that the certificate is valid, and returns a number from 1 through 31, as appropriate for the date. Returns a Boolean TRUE if the time is equal to the <time> argument. For example, if the current time is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month, you can specify the following (evaluation results for this example are in parentheses): w . . .eq(GMT 2005) (TRUE) w . . .eq(GMT 2005 Dec) (FALSE) w . . .eq(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone) w . . .eq(GMT 10h) (TRUE) w . . .eq(GMT 10h 30s) (TRUE) w . . .eq(GMT May 10h) (TRUE) w . . .eq(GMT Sun) (TRUE) w . . .eq(GMT May Sun_1) (TRUE)
<certificate>.VALID_NOT_AFTER. EQ(<time>)
<certificate>.VALID_NOT_AFTER. GE(<time>)
Returns a Boolean TRUE if the time value is greater than or equal to the argument <time>. For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month of May in 2005, you can specify the following (evaluation results for this example are in parentheses): w . . .ge(GMT 2004) (TRUE) w . . .ge(GMT 2005 Jan) (TRUE) w . . .ge(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone.)
169
Chapter 5
Description w . . .ge(GMT 8h) (TRUE) w . . .ge(GMT 30m) (FALSE) w . . .ge(GMT May 10h) (TRUE) w . . .ge(GMT May 10h 0m) (TRUE) w . . .ge(GMT Sun) (TRUE) w . . .ge(GMT May Sun_1) (TRUE)
<certificate>.VALID_NOT_AFTER. GT(<time>)
Returns a Boolean TRUE if the time value is greater than the argument <time>. For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month of May in 2005, you can specify the following (evaluation results for this example are in parentheses): w . . .gt(GMT 2004) (TRUE) w . . .gt(GMT 2005 Jan) (TRUE) w . . .gt(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone.) w . . .gt(GMT 8h) (TRUE) w . . .gt(GMT 30m) (FALSE) w . . .gt(GMT May 10h) (FALSE) w . . .gt(GMT Sun) (FALSE) w . . .gt(GMT May Sun_1) (FALSE)
<certificate>.VALID_NOT_AFTER. HOURS
Extracts the last hour that the certificate is valid and returns that value as an integer from 0 to 23. Returns a Boolean TRUE if the time precedes or is equal to the <time> argument. For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the
<certificate>.VALID_NOT_AFTER. LE(<time>)
170
Description first Sunday of the month of May in 2005, you can specify the following (evaluation results for this example are in parentheses): w . . .le(GMT 2006) (TRUE) w . . .le(GMT 2005 Dec) (TRUE) w . . .le(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone.) w . . .le(GMT 8h) (FALSE) w . . .le(GMT 30m) (TRUE) w . . .le(GMT May 10h) (TRUE) w . . .le(GMT Jun 11h) (TRUE) w . . .le(GMT Wed) (TRUE) w . . .le(GMT May Sun_1) (TRUE)
<certificate>.VALID_NOT_AFTER. LT(<time>)
Returns a Boolean TRUE if the time precedes the <time> argument. For example, if the current time is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month, you can specify the following: w . . .lt(GMT 2006) (TRUE) w . . .lt(GMT 2005 Dec) (TRUE) w . . .lt(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone.) w . . .lt(GMT 8h) (FALSE) w . . .lt(GMT 30m) (TRUE) w . . .lt(GMT May 10h) (FALSE) w . . .lt(GMT Jun 11h) (TRUE) w . . .lt(GMT Wed) (TRUE) w . . .lt(GMT May Sun_1) (FALSE)
171
Chapter 5
Description Extracts the last minute that the certificate is valid and returns that value as an integer from 0 to 59. Extracts the last month that the certificate is valid and returns that value as an integer from 1 (January) to 12 (December). Calculates the number of seconds to the closest previous or scheduled reboot and returns an integer. If the closest boot time is in the past, the integer is negative. If it is in the future, the integer is positive. Calculates the number of seconds between the current system time and the specified time and returns an integer. If the time is in the past, the integer is negative; if it is in the future, the integer is positive. Extracts the last second that the certificate is valid and returns that value as an integer from 0 to 59. Extracts the last weekday that the certificate is valid. Returns a number between 0 (Sunday) and 6 (Saturday) to give the weekday in the time value. Returns a Boolean TRUE if the time lies within all the ranges defined by the elements in <time1> and <time2>. If you omit an element of time from <time1>, it is assumed to have the lowest value in its range. If you omit an element from <time2>, it is assumed to have the highest value of its range. If you specify a year in <time1>, you must specify it in <time2>.
<certificate>.VALID_NOT_AFTER. MONTH
<certificate>.VALID_NOT_AFTER. RELATIVE_BOOT
<certificate>.VALID_NOT_AFTER. RELATIVE_NOW
<certificate>.VALID_NOT_AFTER. SECONDS
<certificate>.VALID_NOT_AFTER. WEEKDAY
172
Description The ranges for elements of time are as follows: month 1-12, day 1-31, weekday 0-6, hour 0-23, minutes 0-59 and seconds 0-59. For the result to be TRUE, each element in the time must exist in the corresponding range that you specify in <time1>, <time2>. For example, if time is GMT 2005 May 10 10h 15m 30s, and it is the second Tuesday of the month, you can specify the following (evaluation results are in parentheses): w . . .within(GMT 2004, GMT 2006) (TRUE) w . . .within(GMT 2004 Jan, GMT 2006 Mar) (FALSE, May is not in the range of January to March.) w . . .within(GMT Feb, GMT) (TRUE, May is in the range for February to December) w . . .within(GMT Sun_1, GMT Sun_3) (TRUE, the second Tuesday lies within the range of the first Sunday through the third Sunday) w . . .within(GMT 2005 May 1 10h, GMT May 2005 1 17h) (TRUE) w . . .within(LOCAL 2005 May 1, LOCAL May 2005 1) (TRUE or FALSE, depending on the NetScaler system time zone)
<certificate>.VALID_NOT_AFTER. YEAR
Extracts the last year that the certificate is valid and returns a fourdigit integer. Returns the date that the client certificate becomes valid.
<certificate>.VALID_NOT_BEFORE
173
Chapter 5
Description The return format is the number of seconds since GMT January 1, 1970 (0 hours, 0 minutes, 0 seconds).
Returns a Boolean TRUE if the time value is between the two time arguments. Both <time1> and <time2> arguments must be fully specified. Following are examples: w GMT 1995 Jan is fully specified. w GMT Jan is not fully specified. w GMT 1995 20 is not fully specified. w GMT Jan Mon_2 is not fully specified. The time arguments must be both GMT or both LOCAL, and <time2> must be greater than <time1>. For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month of May in 2005, you can specify the following (evaluation results for this example are in parentheses): w . . .between(GMT 2004, GMT 2006) (TRUE) w . . .between(GMT 2004 Jan, GMT 2006 Nov) (TRUE) w . . .between(GMT 2004 Jan, GMT 2006) (TRUE) w . . .between(GMT 2005 May Sun_1, GMT 2005 May Sun_3) (TRUE) w . . .between(GMT 2005 May 1, GMT May 2005 1) (TRUE) w . . .between(LOCAL 2005 May 1, LOCAL May 2005 1) (TRUE or FALSE, depending on the NetScaler system time zone.)
174
Description Extracts the last day of the month that the certificate is valid and returns that value as a number from 1 through 31 representing that day. Returns a Boolean TRUE if the time is equal to the <time> argument. For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month of May in 2005, you can specify the following (evaluation results for this example are in parentheses): w . . .eq(GMT 2005) (TRUE) w . . .eq(GMT 2005 Dec) (FALSE) w . . .eq(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone.) w . . .eq(GMT 10h) (TRUE) w . . .eq(GMT 10h 30s) (TRUE) w . . .eq(GMT May 10h) (TRUE) w . . .eq(GMT Sun) (TRUE) w . . .eq(GMT May Sun_1) (TRUE)
<certificate>.VALID_NOT_BEFORE .EQ(<time>)
<certificate>.VALID_NOT_BEFORE .GE(<time>)
Returns a Boolean TRUE if the time is greater than (after) or equal to the <time> argument. For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month of May in 2005, you can specify the following (evaluation results are in parentheses): w . . .ge(GMT 2004) (TRUE) w . . .ge(GMT 2005 Jan) (TRUE) w . . .ge(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone.)
175
Chapter 5
Description w . . .ge(GMT 8h) (TRUE) w . . .ge(GMT 30m) (FALSE) w . . .ge(GMT May 10h) (TRUE) w . . .ge(GMT May 10h 0m) (TRUE) w . . .ge(GMT Sun) (TRUE) w . . .ge(GMT May Sun_1) (TRUE)
<certificate>.VALID_NOT_BEFORE .GT(<time>)
Returns a Boolean TRUE if the time occurs after the <time> argument. For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month of May in 2005, you can specify the following (evaluation results are in parentheses): w . . .gt(GMT 2004) (TRUE) w . . .gt(GMT 2005 Jan) (TRUE) w . . .gt(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone.) w . . .gt(GMT 8h) (TRUE) w . . .gt(GMT 30m) (FALSE) w . . .gt(GMT May 10h) (FALSE) w . . .gt(GMT May 10h 0m) (TRUE) w . . .gt(GMT Sun) (FALSE) w . . .gt(GMT May Sun_1) (FALSE)
<certificate>.VALID_NOT_BEFORE .HOURS
Extracts the last hour that the certificate is valid and returns that value as an integer from 0 to 23. Returns a Boolean TRUE if the time precedes or is equal to the <time> argument.
<certificate>.VALID_NOT_BEFORE .LE(<time>)
176
Description For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month of May in 2005, you can specify the following (evaluation results for this example are in parentheses): w . . .le(GMT 2006) (TRUE) w . . .le(GMT 2005 Dec) (TRUE) w . . .le(LOCAL 2005 May) (TRUE or FALSE,depending on the current time zone.) w . . .le(GMT 8h) (FALSE) w . . .le(GMT 30m) (TRUE) w . . .le(GMT May 10h) (TRUE) w . . .le(GMT Jun 11h) (TRUE) w . . .le(GMT Wed) (TRUE) w . . .le(GMT May Sun_1) (TRUE)
<certificate>.VALID_NOT_BEFORE .LT(<time>)
Returns a Boolean TRUE if the time precedes the <time> argument. For example, if the time value is GMT 2005 May 1 10h 15m 30s, and it is the first Sunday of the month of May in 2005, you can specify the following (evaluation results for this example are in parentheses): w . . .lt(GMT 2006) (TRUE) w . . .lt(GMT 2005 Dec) (TRUE) w . . .lt(LOCAL 2005 May) (TRUE or FALSE, depending on the current time zone.) w . . .lt(GMT 8h) (FALSE) w . . .lt(GMT 30m) (TRUE) w . . .lt(GMT May 10h) (FALSE) w . . .lt(GMT Jun 11h) (TRUE) w . . .lt(GMT Wed) (TRUE) 177
Chapter 5
<certificate>.VALID_NOT_BEFORE .MINUTES
Extracts the last minute that the certificate is valid. Returns the current minute as an integer from 0 to 59. Extracts the last month that the certificate is valid. Returns the current month as an integer from 1 (January) to 12 (December). Calculates the number of seconds to the closest previous or scheduled NetScaler reboot and returns an integer. If the closest boot time is in the past, the integer is negative; if it is in the future, the integer is positive. Returns the number of seconds between the current NetScaler system time and the specified time as an integer. If the designated time is in the past, the integer is negative. If it is in the future, the integer is positive. Extracts the last second that the certificate is valid. Returns the current second as an integer from 0 to 59. Extracts the last weekday that the certificate is valid. Returns the weekday as a number between 0 (Sunday) and 6 (Saturday). Returns a Boolean TRUE if each element of time exists within the range defined in the <time1>, <time2> arguments. If you omit an element of time from <time1>, it is assumed to have the lowest value in its range. If you omit an element of time from <time2>, it is assumed to have the highest value in its range. If you specify a year in <time1>,
<certificate>.VALID_NOT_BEFORE .MONTH
<certificate>.VALID_NOT_BEFORE .RELATIVE_BOOT
<certificate>.VALID_NOT_BEFORE .RELATIVE_NOW
<certificate>.VALID_NOT_BEFORE .SECONDS
<certificate>.VALID_NOT_BEFORE .WEEKDAY
178
Description it must be specified in <time2>. The ranges for elements of time are as follows: month 1-12, day 1-31, weekday 0-6, hour 0-23, minutes 0-59 and seconds 0-59. For example, if the time is GMT 2005 May 10 10h 15m 30s, and it is the second Tuesday of the month, you can specify the following (evaluation results are in parentheses): w . . .within(GMT 2004, GMT 2006) (TRUE) w . . .within(GMT 2004 Jan, GMT 2006 Mar) (FALSE, May is not in the range of January to March.) w . . .within(GMT Feb, GMT) (TRUE, May is in the range of February to December.) w . . .within(GMT Sun_1, GMT Sun_3) (TRUE, the second Tuesday is between the first Sunday and the third Sunday.) w . . .within(GMT 2005 May 1 10h, GMT May 2005 1 17h) (TRUE) w . . .within(LOCAL 2005 May 1, LOCAL May 2005 1) (TRUE or FALSE, depending on the NetScaler system time zone)
<certificate>.VALID_NOT_BEFORE .YEAR
Extracts the last year that the certificate is valid. Returns the current year as a four-digit integer.
Chapter 5
Default Syntax Expressions: Working with Dates, Times, and Numbers w As a number. The numeric value of an HTTP Date header is returned in the form of the number of seconds since Jan 1 1970. For example, the expression http.req.date.mod(86400) returns the number of seconds since the beginning of the day. These values can be evaluated using the same operations as other non-date-related numeric data. For more information, see Expression Prefixes for Numeric Data Other Than Date and Time on page 181. w As an HTTP header. Date headers can be evaluated using the same operations as other HTTP headers. For more information, see Default Syntax Expressions: Parsing HTTP, TCP, and UDP Data on page 187. w As text. Date headers can be evaluated using the same operations as other strings. For more information, see Default Syntax Expressions: Evaluating Text on page 107. Table 5-3. Prefixes That Evaluate HTTP Date Headers Prefix HTTP.REQ.DATE Description Returns the contents of the HTTP Date header as text or as a date object. The date formats recognized are: RFC822. Sun, 06 Jan 1980 08:49:37 GMT RFC850. Sunday, 06-Jan-80 09:49:37 GMT ASCTIME. Sun Jan 6 08:49:37 1980 HTTP.RES.DATE Returns the contents of the HTTP Date header as text or as a date object. The date formats recognized are: RFC822. Sun, 06 Jan 1980 8:49:37 GMT RFC850. Sunday, 06-Jan-80 9:49:37 GMT ASCTIME. Sun Jan 6 08:49:37 1980
Generating the Day of the Week, as a String, in Short and Long Formats
The functions, WEEKDAY_STRING_SHORT and WEEKDAY_STRING, generate the day of the week, as a string, in short and long formats, respectively. The strings that are returned are always in English. The prefix used with these functions must return the day of the week in integer format and the acceptable range for the value returned by the prefix is 0-6. Therefore, you can use any prefix that returns an integer in the acceptable range. An UNDEF condition is raised if the returned value is not in this range or if memory allocation fails. 180
Citrix NetScaler Policy Configuration and Reference Guide Following are the descriptions of the functions: Table 5-4. Functions That Generate the Day of the Week, as a String, in Short and Long Formats Function <prefix>.WEEKDAY_STRING_SHORT Description Returns the day of the week in short format. The short form is always 3 characters long with an initial capital and the remaining characters in lower case. For example, SYS.TIME.WEEKDAY.WEEKDAY_STRIN G_SHORT returns Sun if the value returned by the WEEKDAY function is 0 and Sat if the value returned by the prefix is 6. Returns the day of the week in long format. The long form always has an initial capital, with the remaining characters in lower case. For example, SYS.TIME.WEEKDAY.WEEKDAY_STRIN G returns Sunday if the value returned by the WEEKDAY function is 0 and Saturday if the value returned by the prefix is 6.
<prefix>.WEEKDAY_STRING
Expression Prefixes for Numeric Data Other Than Date and Time
In addition to configuring expressions that operate on time, you can configure expressions for the following types of numeric data: w The length of HTTP requests, the number of HTTP headers in a request, and so on. For more information, see Expressions for HTTP Status Codes and Numeric HTTP Payload Data Other Than Dates on page 207. w IP and MAC addresses. For more information, see Expressions for IP Addresses and IP Subnets on page 250. w Client and server data in regard to interface IDs and transaction throughput rate. For more information, see Expressions for Numeric Client and Server Data on page 257. w Numeric data in client certificates other than dates.
181
Chapter 5
Default Syntax Expressions: Working with Dates, Times, and Numbers For information on these prefixes, including the number of days until certificate expiration and the encryption key size, see Prefixes for Numeric Data in SSL Certificates on page 242.
182
Description Produces a 16-bit unsigned binary string representing the number. If the value is out of range, an undef condition is raised. Example HTTP.REQ.BODY(100).GET_UNSIGNE D16(47, LITTLE_ENDIAN).ADD(7).UNSIGNED 16_STRING(LITTLE_ENDIAN)
<number>.SIGNED32_STRING(<endi anness>)
Produces a 32-bit signed binary string representing the number. Example HTTP.REQ.BODY(100).AFTER_STR(" delim").GET_SIGNED32(0, BIG_ENDIAN).SUB(1).SIGNED32_ST RING(BIG_ENDIAN)
<unsigned_long_number>.UNSIGNE D8_STRING
Produces an 8-bit unsigned binary string representing the number. If the value is out of range, an undef condition is raised. Example HTTP.REQ.BODY(100).GET_UNSIGNE D8(24).TYPECAST_UNSIGNED_LONG_ AT.ADD(12).UNSIGNED8_STRING
<unsigned_long_number>.UNSIGNE D16_STRING(<endianness>)
Produces a 16-bit unsigned binary string representing the number. If the value is out of range, an undef condition is raised. Example HTTP.REQ.BODY(100).GET_UNSIGNE D16(23, LITTLE_ENDIAN).TYPECAST_UNSIGN ED_LONG_AT.ADD(10).UNSIGNED16_ STRING(LITTLE_ENDIAN)
<unsigned_long_number>.UNSIGNE D32_STRING(<endianness>)
Produces a 32-bit unsigned binary string representing the number. If the value is
183
Chapter 5
Function
Description out of range, an undef condition is raised. Example HTTP.REQ.BODY(100).AFTER_STR(" delim2").GET_UNSIGNED32(0, BIG_ENDIAN).ADD(2).UNSIGNED32_ STRING(BIG_ENDIAN)
Citrix NetScaler Policy Configuration and Reference Guide add rewrite policy norewrite_pol sys.vserver("LBvserver").connections.gt(10000) norewrite Example 2 The following rewrite action inserts a custom header, TP, whose value is the throughout at the virtual server LBvserver: add rewrite action tp_header insert_http_header TP SYS.VSERVER("LBvserver").THROUGHPUT Example 3 The following audit log message action writes the average TTFB of the services bound to a virtual server, to the newnslog log file: add audit messageaction log_vserver_resptime_act INFORMATIONAL "\"NS Response Time to Servers:\" + sys.vserver(\"ssllb \").resptime + \" millisec\"" -logtoNewnslog YES bypassSafetyCheck YES
185
Chapter 5
186
Chapter 6
187
Chapter 6
188
Citrix NetScaler Policy Configuration and Reference Guide Following is an example that evaluates to TRUE if a response body of 1024 bytes contains the string https, and this string occurs after the string start string and before the string end string: http.res.body(1024).after_str("start_string").before_str("end_str ing").contains("https") Note: You can apply any text operation to the payload body. For information on operations that you can apply to text, see Default Syntax Expressions: Evaluating Text on page 107.
CLIENT.IPV6.PROTOCOL
SERVER.IP.PROTOCOL
SERVER.IPV6.PROTOCOL
189
Chapter 6
Protocol Transmission Control Protocol (TCP) User Datagram Protocol (UDP) Internet Control Message Protocol (ICMP) IP Authentication Header (AH), for providing authentication services in IPv4 and IPv6 Encapsulating Security Payload (ESP) protocol General Routing Encapsulation (GRE) IP-within-IP Encapsulation Protocol Internet Control Message Protocol for IPv6 (ICMPv6) Fragment Header for IPv6
190
191
Chapter 6
Description Returns the contents of the HTTP Date header. The following date formats are recognized: RFC822. Sun, 06 Jan 1980 8:49:37 GMT RFC850. Sunday, 06-Jan-80 9:49:37 GMT ASCII TIME. Sun Jan 6 08:49:37 1980 To evaluate a Date header as a date object, see Default Syntax Expressions: Working with Dates, Times, and Numbers on page 159.
HTTP.REQ.COOKIE
(Name/Value List) Returns the contents of the HTTP Cookie header. Returns the HTTP transaction ID. The value is a function of an internal transaction number, system boot time and system MAC address. Returns the contents of the HTTP header specified by the <header_name> argument. The header name cannot exceed 32 characters. Returns the contents of the complete set of HTTP header fields including the status line (for example, "HTTP/1.1 200 OK") and the terminating \r\n\r\n sequence. Returns the HTTP Set-Cookie header object in a response.
HTTP.REQ.TXID
HTTP.RES.HEADER("<header_name> ")
HTTP.RES.FULL_HEADER
Returns the cookie of the specified name if it is present. If it is not present, returns a text object of length 0. Returns UNDEF if more than 15 Set-Cookie headers are present and the specified cookie was not found in these headers.
192
Description Returns the value of the first Domain field in the cookie. For example, if the cookie is Set-Cookie : Customer = "ABC"; DOMAIN=".abc.com"; DOMAIN=.xyz.com, the following expression returns .abc.com: http.res.set_cookie.cookie("cu stomer").domain A string of zero length is returned if the Domain field or its value is absent.
Returns a Boolean TRUE if a Cookie with the name specified in the <name> argument exists in the Set-Cookie header. This prefix returns UNDEF if more than 15 Set-Cookie headers are present and the named cookie is not in the first 15 headers. Returns the Expires field of the cookie. This is a date string that can be evaluated as a number, as a time object, or as text. If multiple Expires fields are present, the first one is returned. If the Expires field is absent, a text object of length zero is returned. To evaluate the returned value as a time object, see Default Syntax Expressions: Working with Dates, Times, and Numbers on page 159.
Returns the value of Path field of the cookie as a slash- (/) separated list. Multiple instances of a slash are treated as single slash. If multiple Path fields are present, the value of the first instance is returned. For example, the following is a cookie with two path fields: Set-Cookie : Customer = "ABC"; PATH="/a//b/c"; PATH= "/x/y/z"
193
Chapter 6
Description The following expression returns /a//b/ c from this cookie: http.res.set_cookie.cookie("Cu stomer").path The following expression returns b: http.res.set_cookie.cookie("Cu stomer").path.get(2) Quotes are stripped from the returned value. A string of zero length is returned if the Path field or its value is absent.
Ignores the empty elements in the list. For example, in the list a=10,b=11, ,c=89, the element delimiter in the list is , and the list has an empty element following a=10. The element following b=11 is not considered an empty element. As another example, in the following expression, if a request contains Cust_Header : 123,,24, ,15 the following expression returns a value of 4: http.req.header("Cust_Header") .typecast_list_t(',').ignore_e mpty_elements.count The following expression returns a value of 5: http.req.header("Cust_Header") .typecast_list_t(',').count
Returns the value of Port field of the cookie. Operate as a comma-separated list. For example, the following expression returns 80. 2580 from Set-Cookie : Customer = "ABC"; PATH="/a/b/c"; PORT= "80, 2580": http.res.set_cookie.cookie("AB C").port
194
Description A string of zero length is returned if the Port field or value is absent.
Ignores the empty elements in the list. For example, in the list a=10,b=11, ,c=89, the element delimiter in the list is , and the list has an empty element following a=10. The element following b=11 is not considered an empty element. As another example, in the following expression, if a request contains Cust_Header : 123,,24, ,15 the following expression returns a value of 4: http.req.header("Cust_Header") .typecast_list_t(',').ignore_e mpty_elements.count The following expression returns a value of 5: http.req.header("Cust_Header") .typecast_list_t(',').count
Returns the value of the first Version field in the cookie as a decimal integer. For example, the following expression returns 1 from the cookie Set-Cookie : Customer = "ABC"; VERSION = "1"; VERSION = "0" http.res.set_cookie.cookie("CU STOMER").version A zero is returned if the Version field or its value is absent or if the value is not a decimal number.
Returns the nth instance (0-based) of the cookie with the specified name. If the cookie is absent, returns a text object of length 0. Returns UNDEF if more than 15 SetCookie headers are present and the cookie is not found. 195
Chapter 6
Description Returns the value of the Domain field of the first cookie with the specified name. For example, the following expression returns a value of abc.com from the cookie Set-Cookie : Customer = "ABC"; DOMAIN=".abc.com"; DOMAIN=.xyz.com http.res.set_cookie.cookie("CU STOMER").domain A string of zero length is returned if the Domain field or its value is absent.
HTTP.RES.SET_COOKIE.COOKIE("<n ame>", <integer>).EXPIRES or HTTP.RES.SET_COOKIE2.COOKIE("< name>", <integer>).EXPIRES HTTP.RES.SET_COOKIE.COOKIE("<n ame>", <integer>).PATH | PATH.GET(i) or HTTP.RES.SET_COOKIE2.COOKIE("< name>", <integer>).PATH | PATH.GET(i)
Returns the nth instance (0-based) of the Expires field of the cookie with the specified name as a date string. The value can be operated upon as a time object that supports a number of date formats. If the Expires attribute is absent a string of length zero is returned. Returns the value of the Path field of the nth cookie, as a '/' separated list. Multiple /s are treated as a single /. For example, the following expression returns /a//b/c from the cookie SetCookie : Customer = "ABC"; PATH="/a// b/c"; PATH= "/x/y/z" http.res.set_cookie.cookie("CU STOMER").path The following returns b: http.res.set_cookie.cookie("CU STOMER").path.get(2) A string of zero length is returned if the Path field or its value is absent.
Ignores the empty elements in the list. For example, in the list a=10,b=11, ,c=89, the element delimiter in the list is , and the list has an empty element following a=10. The element following b=11 is not considered an empty element.
196
Description As another example, in the following expression, if a request contains Cust_Header : 123,,24, ,15 the following expression returns a value of 4: http.req.header("Cust_Header") .typecast_list_t(',').ignore_e mpty_elements.count The following expression returns a value of 5: http.req.header("Cust_Header") .typecast_list_t(',').count
Returns the value or values of the Port field of the named cookie as a ',' separated list. For example, the following expression returns 80, 2580 from the cookie Set-Cookie : Customer = "ABC"; PATH="/a/b/c"; PORT= "80, 2580" http.res.set_cookie.cookie("AB C").port A string of zero length is returned if the Port field or its value is absent.
Ignores the empty elements in the list. For example, in the list a=10,b=11, ,c=89, the element delimiter in the list is , and the list has an empty element following a=10. The element following b=11 is not considered an empty element. As another example, in the following expression, if a request contains Cust_Header : 123,,24, ,15 the following expression returns a value of 4: http.req.header("Cust_Header") .typecast_list_t(',').ignore_e mpty_elements.count The following expression returns a value of 5:
197
Chapter 6
Returns the value of Version field of the nth cookie as a decimal integer. A string of zero length is returned if the Port field or its value is absent.
Returns the HTTP transaction ID. The value is a function of an internal transaction number, system boot time and system MAC address.
198
Content-Length: 200\r\n MyHeader: def\r\n \r\n The following returns a Boolean TRUE: http.res.header("MyHeader"). contains("de") The following returns FALSE. Note that the NetScaler does not concatenate the different values. http.res.header("MyHeader"). contains("bcd") http header .COUNT Returns the number of headers in a request or response, to a maximum of 15 headers of the same type. The result is undefined if there are more than 15 instances of the header. Following is sample data in a request: HTTP/1.1 200 OK\r\n MyHeader: abc\r\n Content-Length: 200\r\n MyHeader: def\r\n \r\n When evaluating the preceding request, the following returns a count of 2: http.res.header("MyHeader").co unt http header.AFTER_STR("<string>") Extracts the text that follows the first occurrence of the <string> argument. The headers are evaluated from the last instance to the first. Following is an example of a request: HTTP/1.1 200 OK\r\n MyHeader: 111abc\r\n Content-Length: 200\r\n
199
Chapter 6
MyHeader: 111def\r\n \r\n The following extracts the string "def" from the last instance of MyHeader. This is value "111def." http.res.header("MyHeader").af ter_str("111") The following extracts the string "c" from the first instance of MyHeader. This is the value "abc111." http.res.header("MyHeader").af ter_str("1ab") http header.BEFORE_STR("<string>") Extracts the text that appears prior to the first occurrence of the input <string> argument. The headers are evaluated from the last instance to the first. Following is an example of a request that contains headers: HTTP/1.1 200 OK\r\n MyHeader: abc111\r\n Content-Length: 200\r\n MyHeader: def111\r\n \r\n The following extracts the string "def" from the last instance of MyHeader. This is the value "def111." http.res.header("MyHeader").be fore_str("111") The following extracts the string "a" from the first instance of MyHeader. This is the value "abc111." http.res.header("MyHeader").be fore_str("bc1") http header.INSTANCE(<instance number>) An HTTP header can occur multiple times in a request or a response. This operation returns the header that occurs <instance number> of places before the
200
final instance. For example, instance(0) selects the last instance of the current type, instance(1) selects the next-to-last instance, and so on. This prefix cannot be used in bidirectional policies. The <instance number> argument cannot exceed 14. Following is an example of a request with two headers: HTTP/1.1 200 OK\r\n MyHeader: abc\r\n Content-Length: 200\r\n MyHeader: def\r\n \r\n The following returns a text object that refers to "MyHeader: abc\r\n": http.res.header("MyHeader").in stance(1) http header.SUBSTR("<string>") Extracts the text that matches the <string> argument. The headers are evaluated from the last instance to the first. Following is an example of a request with two headers that contain the string 111: HTTP/1.1 200 OK\r\n MyHeader: abc111\r\n Content-Length: 200\r\n MyHeader: 111def\r\n \r\n The following returns "111" from the last instance of MyHeader. This is the header with the value "111def." http.res.header("MyHeader").su bstr("111") http header.VALUE(<instance number>) An HTTP header can occur multiple times in a request or a response. VALUE(0) selects the value in the last instance, VALUE(1) selects the value in 201
Chapter 6
the next-to-last instance, and so on. The <instance number> argument cannot exceed 14. Following is an example of a request with two headers: HTTP/1.1 200 OK\r\n MyHeader: abc\r\n Content-Length: 200\r\n MyHeader: def\r\n \r\n The following returns "abc\r\n": http.res.header("MyHeader").va lue(1)
HTTP.RES.CACHE_CONTROL
202
Citrix NetScaler Policy Configuration and Reference Guide Table 6-4. Operations That Evaluate Cache-Control Headers HTTP Header Operation Cache-Control header.NAME(<integer>) Description Returns as a text value the name of the Cache-Control header that corresponds to the nth component in a name-value list, as specified by <integer>. The index of the name-value component is 0-based. If the <integer> that is specified by the integer argument is greater than the number of components in the list, a zero-length text object is returned. Following is an example: http.req.cache_control.name(3) .contains("some_text") Cache-Control header.IS_INVALID Returns a Boolean TRUE if the CacheControl header is not present in the request or response. Following is an example: http.req.cache_control.is_inva lid Cache-Control header.IS_PRIVATE Returns a Boolean TRUE if the CacheControl header has the value Private. Following is an example: http.req.cache_control.is_priv ate Cache-Control header.IS_PUBLIC Returns a Boolean TRUE if the CacheControl header has the value Private. Following is an example: http.req.cache_control.is_publ ic Cache-Control header.IS_NO_STORE Returns a Boolean TRUE if the CacheControl header has the value No-Store. Following is an example:
203
Chapter 6
Cache-Control header.IS_NO_CACHE
Returns a Boolean TRUE if the CacheControl header has the value No-Cache. Following is an example: http.req.cache_control.is_no_c ache
Cache-Control header.IS_MAX_AGE
Returns a Boolean TRUE if the CacheControl header has the value Max-Age. Following is an example: http.req.cache_control.is_max_ age
Cache-Control header.IS_MIN_FRESH
Returns a Boolean TRUE if the CacheControl header has the value Min-Fresh. Following is an example: http.req.cache_control.is_min_ fresh
Cache-Control header.IS_MAX_STALE
Returns a Boolean TRUE if the CacheControl header has the value Max-Stale. Following is an example: http.req.cache_control.is_max_ stale
Cache-Control header.IS_MUST_REVALIDATE
Returns a Boolean TRUE if the CacheControl header has the value MustRevalidate. Following is an example: http.req.cache_control.is_must _revalidate
Cache-Control header.IS_NO_TRANSFORM
Returns a Boolean TRUE if the CacheControl header has the value NoTransform. Following is an example:
204
Cache-Control header.IS_ONLY_IF_CACHED
Returns a Boolean TRUE if the CacheControl header has the value Only-IfCached. Following is an example: http.req.cache_control.is_only _if_cached
Cache-Control header.IS_PROXY_REVALIDATE
Returns a Boolean TRUE if the CacheControl header has the value ProxyRevalidate. Following is an example: http.req.cache_control.is_prox y_revalidate
Cache-Control header.IS_S_MAXAGE
Returns a Boolean TRUE if the CacheControl header has the value S-Maxage. Following is an example: http.req.cache_control.is_s_ma xage
Cache-Control header.IS_UNKNOWN
Returns a Boolean TRUE if the CacheControl header is of an unknown type. Following is an example: http.req.cache_control.is_unkn own
Cache-Control header.MAX_AGE
Returns the value of the Cache-Control header Max-Age. If this header is absent or invalid, 0 is returned. Following is an example: http.req.cache_control.max_age .le(3)
205
Chapter 6
Description Returns the value of the Cache-Control header Max-Stale. If this header is absent or invalid, 0 is returned. Following is an example: http.req.cache_control.max_sta le.le(3)
Cache-Control header.MIN_FRESH
Returns the value of the Cache-Control header Min-Fresh. If this header is absent or invalid, 0 is returned. Following is an example: http.req.cache_control.min_fre sh.le(3)
Cache-Control header.S_MAXAGE
Returns the value of the Cache-Control header S-Maxage. If this header is absent or invalid, 0 is returned. Following is an example: http.req.cache_control.s_maxag e.eq(2)
206
Citrix NetScaler Policy Configuration and Reference Guide Table 6-5. Prefixes That Extract URLs URL Prefix HTTP.REQ.URL.PATH.GET(<n>) Description Returns a slash- (/) separated list from the URL path. For example, consider the following URL: http://www.mycompany.com/dir1/ dir2/dir3/index.html?a=1 The following expression returns dir1 from this URL: http.req.url.path.get(1) The following expression returns dir2: http.req.url.path.get(2) HTTP.REQ.URL.PATH.GET_REVERSE( <n>) Returns a slash- (/) separated list from the URL path, starting from the end of the path. For example, consider the following URL: http://www.mycompany.com/dir1/ dir2/dir3/index.html?a=1 The following expression returns index.html from this URL: http.req.url.path.get_reverse( 0) The following expression returns dir3: http.req.url.path.get_reverse( 1)
Expressions for HTTP Status Codes and Numeric HTTP Payload Data Other Than Dates
The following table describes prefixes for numeric values in HTTP data other than dates.
207
Chapter 6
Default Syntax Expressions: Parsing HTTP, TCP, and UDP Data Table 6-6. Prefixes That Evaluate HTTP Request or Response Length Prefix HTTP.REQ.CONTENT_LENGTH Description Returns the length of an HTTP request as a number. Following is an example: http.req.content_length < 500 HTTP.RES.CONTENT_LENGTH Returns the length of the HTTP response as a number. Following is an example: http.res.content_length <= 1000 HTTP.RES.STATUS HTTP.RES.IS_REDIRECT Returns the response status code Returns a Boolean TRUE if the response code is associated with a redirect. Following are the redirect response codes: w 300 (Multiple Choices) w 301 (Moved Permanently) w 302 (Found) w 303 (See Other) w 305 (Use Proxy) w 307 (Temporary Redirect) Note: Status code 304 is not considered a redirect HTTP response status code. Status code 306 is unused. In the following example, the rewrite action replaces http in the Location header of an HTTP response with https if the response is associated with an HTTP redirect. add rewrite action redloc replace 'http.res.header("Location").b efore_regex(re#://#)' '"https"'
208
Prefix
Description add rewrite policy pol1 HTTP.RES.IS_REDIRECT red_location bind rewrite global pol1 100
SIP Expressions
Introduction
The NetScaler default expressions language contains a number of expressions that operate on Session Initiation Protocol (SIP) connections. These expressions are intended to be used in policies for any supported protocol that operates on a request/response basis. (These expressions can be bound only to sip_udp virtual servers and global bind points.) These expressions can be used in content switching, rate limiting, responder, and rewrite policies. Certain limitations apply to SIP expressions used with responder policies. The NetScaler operating system currently supports only SIP over UDP. Only the DROP, NOOP or RESPONDWITH actions are allowed on a SIP load balancing virtual server. Responder policies can be bound to a load balancing virtual server, an override global bind point, a default global bind point, or a sip_udp policy label. The header format used by the SIP protocol is similar to that used by the HTTP protocol, so many of the new expressions look and function much like their HTTP analogs. Each SIP header consists of a line that includes the SIP method, the URL, and the version, followed by a series of name-value pairs that look like HTTP headers. Following is a sample SIP header that is referred to in the expressions tables beneath it: INVITE sip:16@www.sip.com:5060;transport=udp SIP/2.0 Record-Route: <sip:200.200.100.22;lr=on> Via: SIP/2.0/UDP 200.200.100.22;branch=z9hG4bK444b.c8e103d1.0;rport=5060; received=10.102.84.18 Via: SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG4bK03e76d0b;rport=5060; received=10.102.84.160 From: "12" <sip: 12@sip_example.com>;tag=00127f54ec85a6d90cc14f45-53cc0185 To: "16" <sip: 16@sip_example.com>;tag=00127f54ec85a6d90cc14f45-53cc0185 Call-ID: 00127f54-ec850017-0e46f5b9-5ec149c2@10.102.84.180 Max-Forwards: 69CSeq: 101 INVITE User-Agent: Cisco-CP7940G/8.0 Contact: <sip:12@10.102.84.180:5060;transport=udp> Expires: 180 Accept: application/sdp Allow: ACK,BYE,CANCEL,INVITE,NOTIFY,OPTIONS,REFER,REGISTER,UPDATE 209
Chapter 6
Default Syntax Expressions: Parsing HTTP, TCP, and UDP Data Supported: replaces,join,norefersub Content-Length: 277 Content-Type: application/sdp Content-Disposition: session;handling=optiona
SIP.REQ.URL
210
Expression SIP.REQ.URL.PROTOCOL
Description Returns the URL protocol. For example, for a SIP URL of sip:16@www.sip.com: 5060;transport=udp, this expression returns sip. Returns the hostname portion of the SIP URL. For example, for a SIP URL of sip: 16@www.sip.com: 5060;transport=udp, this expression returns www.sip.com:5060. Returns the port portion of the SIP URL hostname. If no port is specified, this expression returns the default SIP port, 5060. For example, for a SIP hostname of www.sip.com:5060, this expression returns 5060. Returns the domain name portion of the SIP URL hostname. If the host is an IP address, then this expression returns an incorrect result. For example, for a SIP hostname of www.sip.com:5060, this expression returns sip.com. For a SIP hostname of 192.168.43.15:5060, this expression returns an error. Returns the server portion of the host. For example, for a SIP hostname of www.sip.com:5060, this expression returns www. Returns the username that precedes the @ character. For example, for a SIP URL of sip:16@www.sip.com: 5060;transport=udp, this expression returns 16. Returns the SIP version number in the request. For example, for a SIP request of INVITE sip: 16@10.102.84.181:5060;transpor t=udp SIP/2.0, this expression returns SIP/2.0. 211
SIP.REQ.URL.HOSTNAME
SIP.REQ.URL.HOSTNAME.PORT
SIP.REQ.URL.HOSTNAME.DOMAIN
SIP.REQ.URL.HOSTNAME.SERVER
SIP.REQ.URL.USERNAME
SIP.REQ.VERSION
Chapter 6
Expression SIP.REQ.VERSION.MAJOR
Description Returns the major version number (the number to the left of the period). For example, for a SIP version number of SIP/2.0, this expression returns 2. Returns the minor version number (the number to the right of the period). For example, for a SIP version number of SIP/2.0, this expression returns 0. Returns the contents of the ContentLength header. This expression is a derivative of the sip_header_t class, so all operations that are available for SIP headers can be used. For example, for a SIP Content-Length header of Content-Length: 277, this expression returns 277. Returns the contents of the To header. For example, for a SIP To header of To: "16" <sip: 16@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185, this expression returns "16" <sip: 16@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185. Returns the SIP URI, which is found in the sip_url object. All operations that are available for SIP URIs can be used. For example, for a SIP To header of To: "16" <sip: 16@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185, this expression returns sip: 16@sip_example.com. Returns the display name portion of the To header. For example, for a SIP To header of To: "16" <sip: 16@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185, this expression returns 16.
SIP.REQ.VERSION.MINOR
SIP.REQ.CONTENT_LENGTH
SIP.REQ.TO
SIP.REQ.TO.ADDRESS
SIP.REQ.TO.DISPLAY_NAME
212
Expression SIP.REQ.TO.TAG
Description Returns the tag vale from the tag name value pair in the TO header. For example, for a SIP To header of To: "16" <sip: 16@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185, this expression returns 00127f54ec85a6d90cc14f45-53cc0 185. Returns the contents of the From header. For example, for a SIP From header of From: "12" <sip: 12@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185, this expression returns sip: 12@sip_example.com. Returns the SIP URI, which is found in the sip_url object. All operations that are available for SIP URIs can be used. For example, for a SIP From header of From: "12" <sip: 12@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185, this expression returns sip: 12@sip_example.com. Returns the display name portion of the To header. For example, for a SIP From header of From: "12" <sip: 12@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185, this expression returns 12. Returns the tag value from the tag name/value pair in the TO header. For example, for a SIP From header of From: "12" <sip: 12@sip_example.com>;tag=00127f 54ec85a6d90cc14f45-53cc0185, this expression returns 00127f54ec85a6d90cc14f45-53cc0 185.
SIP.REQ.FROM
SIP.REQ.FROM.ADDRESS
SIP.REQ.FROM.DISPLAY_NAME
SIP.REQ.FROM.TAG
213
Chapter 6
Expression SIP.REQ.VIA
Description Returns the complete Via header. If there are multiple Via headers in the request, returns the last Via header. For example, for the two Via headers in the sample SIP header, this expression returns Via: SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160. Returns the address that sent the request. For example, for the Via header Via: SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, this expression returns 10.102.84.180. Returns the port that sent the request. For example, for the Via header Via: SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, this expression returns 5060. Returns the value from the rport name/ value pair. For example, for the Via header Via: SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, this expression returns 5060. Returns the value from the branch name/ value pair. For example, for the Via header Via: SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, this expression returns z9hG4bK03e76d0b. Returns the value from the received name/value pair. For example, for the
SIP.REQ.VIA.SENTBY_ADDRESS
SIP.REQ.VIA.SENTBY_PORT
SIP.REQ.VIA.RPORT
SIP.REQ.VIA.BRANCH
SIP.REQ.VIA.RECEIVED
214
Expression
Description Via header Via: SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, this expression returns 10.102.84.160.
SIP.REQ.CALLID
Returns the contents of the Callid header. This expression is a derivative of the sip_header_t class, so all operations that are available for SIP headers can be used. For example, for a SIP Callid header of Call-ID: 00127f54ec850017-0e46f5b9-5ec149c2@10. 102.84.180, this expression returns 00127f54ec850017-0e46f5b9-5ec149c2@10. 102.84.180. Returns the CSEQ number from the CSEQ, as an integer. For example, for a SIP CSEQ header of CSeq: 101 INVITE, this expression returns 101. Returns the specified SIP header. For <header_name>, substitute the name of the header that you want. For example, to return the SIP From header, you would type SIP.REQ.HEADER("From"). Returns the specified instance of the specified SIP header. Multiple instances of the same SIP header can occur. Where you want a specific instance of such a SIP header (for example, a specific Via header), you can specify that header by typing a number as the <line_number>. Header instances are matched from last (0) to first. In other words, SIP.REQ.HEADER("Via").INSTANCE (0) returns the last instance of the Via header, while SIP.REQ.HEADER("Via").INSTANCE 215
SIP.REQ.CSEQ
SIP.REQ.HEADER("<header_name>" )
SIP.REQ.HEADER("<header_name>" ).INSTANCE(<line_number>)
Chapter 6
Expression
Description (1) returns the last instance but one of the Via header, and so on. For example, if used on the example SIP header, SIP.REQ.HEADER("Via").INSTANCE (1) returns Via: SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060.
SIP.REQ.HEADER("<header_name>" ).VALUE(<line_number>)
Returns the contents of the specified instance of the specified SIP header. The usage is nearly the same as the previous expression. For example, if used on the SIP header example in the preceding table entry, SIP.REQ.HEADER(Via).VALUE(1) returns SIP/2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060. Returns the number of instances of a particular header as an integer. For example, if used on the SIP header example above, SIP.REQ.HEADER(Via).COUNT returns 2. Returns a boolean value of true or false, depending upon whether the specified header exists or not. For example, if used on the SIP header example above, SIP.REQ.HEADER(Expires).EXIS TS returns true, while SIP.REQ.HEADER(CallerID).EXISTS returns false. Returns the comma-separated parameter list in the specified header. For example, if used on the SIP header example above, SIP.REQ.HEADER(Allow).LIST returns ACK,BYE,CANCEL,INVITE,NOTIFY,OPTION S,REFER,REGISTER,UPDATE.
SIP.REQ.HEADER("<header_name>" ).COUNT
SIP.REQ.HEADER("<header_name>" ).EXISTS
SIP.REQ.HEADER("<header_name>" ).LIST
216
Expression
Description You can append the string .GET(<list_item_number>) to select a specific list item. For example, to get the first item (ACK) from the above list, you would type SIP.REQ.HEADER(Allow).LIST.GET(0). To extract the second item (BYE), you would type SIP.REQ.HEADER(Allow).LIST.GET(1). Note: If the specified header contains a list of name/value pairs, the entire name/value pair is returned.
Typecasts <header_name> to <in_header_name>. Any text can be typecasted to the sip_header_t class, after which all header-based operations can be used. After you perform this operation, you can apply all operations that can be used with <in_header_name>. For example, the expression SIP.REQ.CONTENT_LENGTH.TYPECAS T_SIP_HEADER_T typecasts all instances of the Content-Length header. After you perform this operation, you can apply all header operations to all instances of the specified header.
SIP.REQ.HEADER("<header_name>" ).CONTAINS("<string>").
Returns boolean true if the specified text string is present in any instance of the specified header. Operates on all the instances of the specified header. Header instances are matched from last (0) to first. Returns boolean true if any pattern associated with <patset> matches any content in any instance of the specified header. Operates on all the instances of the specified header. Header instances are matched from last (0) to first.
SIP.REQ.HEADER("<header_name>" ).EQUALS_ANY(<patset>)
217
Chapter 6
Description Returns Boolean true if any pattern associated with <patset> matches any content in any instance of the specified header. Operates on all the instances of the specified header. Header instances are matched from last (0) to first. Returns the index of the matching pattern associated with <patset> if that pattern matches any content in any instance of the specified header. Operates on all the instances of the specified header. Header instances are matched from last (0) to first. Returns the index of the matching pattern associated with <patset> if that pattern matches any instance of the specified header. Operates on all the instances of the specified header. Header instances are matched from last (0) to first. If the specified string is present in any instance of the specified header, this expression returns that string. For example, for the SIP header Via: SIP/ 2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, SIP.REQ.HEADER("Via").SUBSTR(" rport=5060") returns rport=5060. SIP.REQ.HEADER("Via").SUBSTR(" rport=5061") returns an empty string. If the specified string is present in any instance of the specified header, this expression returns the string immediately after that string. For example, for the SIP header Via: SIP/ 2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, the expression
SIP.REQ.HEADER("<header_name>" ).CONTAINS_INDEX(<patset>)
SIP.REQ.HEADER("<header_name>" ).EQUALS_INDEX(<patset>)
SIP.REQ.HEADER("<header_name>" ).SUBSTR("<string>")
SIP.REQ.HEADER("<header_name>" ).AFTER_STR("<string>")
218
Expression
SIP.REQ.HEADER("<header_name>" ).REGEX_MATCH(<regex>)
Returns boolean true if the specified regular expression (regex) matches any instance of the specified header. You must specify the regular expression in the following format: re<delimiter>regular expression<same delimiter> The regular expression cannot be larger than 1499 characters in length. It must conform to the PCRE regular expression library. See http://www.pcre.org/ pcre.txt for documentation on PCRE regular expression syntax. The pcrepattern man page also has useful information on specifying patterns by using PCRE regular expressions. The regular expression syntax supported in this expression has some differences from PCRE. Back references are not allowed. You should avoid recursive regular expressions; although some work, many do not. The dot (.) metacharacter matches newlines. Unicode is not supported. SET_TEXT_MODE(IGNORECASE) overrides the (?i) internal option specified in the regular expression.
SIP.REQ.HEADER("<header_name>" ).REGEX_SELECT(<regex>)
If the specified regex matches any text in any instance of the specified header, this expression returns the text. For example, for the SIP header Via: SIP/ 2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, the expression SIP.REQ.HEADER("Via").REGEX_SE LECT("received=[0-9]{1,3}\. [0-9]{1,3}\.[0-9]{1,3}\.[0-9] {1,3}") returns received=10.102.84.160.
219
Chapter 6
Description If the specified regex matches any text in any instance of the specified header, this expression returns the string immediately after that text. For example, for the SIP header Via: SIP/ 2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, the expression SIP.REQ.HEADER("Via").AFTER_RE GEX("received=") returns 10.102.84.160. If the specified regex matches any text in any instance of the specified header, this expression returns the string immediately before that text. For example, for the SIP header Via: SIP/ 2.0/UDP 10.102.84.180:5060;branch=z9hG 4bK03e76d0b;rport=5060;receive d=10.102.84.160, the expression SIP.REQ.HEADER("Via").BEFORE_R EGEX("[0-9]{1,3}\.[0-9]{1,3}\. [0-9]{1,3}\.[0-9]{1,3}") returns received=. Returns the entire SIP header, including the terminating CR/LF. Returns boolean true if the request format is valid. Returns the request body, up to the specified length. If the specified length is greater than the length of the request body, this expression returns the entire request body. Returns the name of the load balancing virtual server (LB vserver) that is serving the current request.
SIP.REQ.HEADER("<header_name>" ).BEFORE_REGEX(<regex>)
SIP.REQ.FULL_HEADER
SIP.REQ.IS_VALID
SIP.REQ.BODY(<length>)
SIP.REQ.LB_VSERVER
220
Expression SIP.REQ.CS_VSERVER
Description Returns the name of the content switching virtual server (CS vserver) that is serving the current request.
Table 6-8. SIP Response Expressions Expression SIP.RES.STATUS Description Returns the SIP response status code. For example, if the first line of the response is SIP/2.0 100 Trying, this expression returns 100. Returns the SIP response status message. For example, if the first line of the response is SIP/2.0 100 Trying, this expression returns Trying. Returns boolean true if the response code is a redirect. Returns the response method extracted from the request method string in the CSeq header.
SIP.RES.STATUS_MSG
SIP.RES.IS_REDIRECT
SIP.RES.METHOD
Operations for HTTP, HTML, and XML Encoding and Safe Characters
The following operations work with the encoding of HTML data in a request or response and XML data in a POST body. Table 6-9. Operations That Evaluate HTML and XML Encoding HTML or XML Operation <text>.HTML_XML_SAFE Description Transforms special characters into XML safe format, as in the following examples: w A left-pointing angle bracket (<) is converted to < 221
Chapter 6
Description w A right-pointing angle bracket (>) is converted to > w An ampersand (&) is converted to & This operation safeguards against crosssite scripting attacks. Maximum length of the transformed text is 2048 bytes. This is a read-only operation. After applying the transformation, additional operators that you specify in the expression are applied to the selected text. Following is an example: http.req.url.query.html_xml_sa fe. contains("myQueryString")
<text>.HTTP_HEADER_SAFE
Converts all new line ('\n') characters in the input text to '%0A' to enable the input to be used safely in HTTP headers. This operation safeguards against response-splitting attacks. The maximum length of the transformed text is 2048 bytes. This is a read-only operation.
<text>.HTTP_URL_SAFE
Converts unsafe URL characters to '%xx' values, where xx is a hex-based representation of the input character. For example, the ampersand (&) is represented as %26 in URL-safe encoding. The maximum length of the transformed text is 2048 bytes. This is a read-only operation. Following are URL safe characters. All others are unsafe: w Alpha-numeric characters: a-z, A-Z, 0-9 w Asterix: "*" w Ampersand: "&" w At-sign: "@"
222
Description w Colon: ":" w Dollar: "$" w Dot: "." w Equals: "=" w Exclamation mark: "!" w Hyphen: "-" w Open and close parentheses: "(", ")" w Plus: "+" w Semicolon: ";" w Single quote: "'" w Slash: "/" w Tilde: "~" w Underscore: "_"
<text>.MARK_SAFE
Marks the text as safe without applying any type of data transformation. Transforms all %HH encoding in the byte stream. This operation works with characters (not bytes). By default, a single byte represents a character in ASCII encoding. However, if you specify URLENCODED mode, three bytes can represent a character. In the following example, a PREFIX(3) operation selects the first 3 characters in a target. http.req.url.hostname.prefix(3 ) In the following example, the NetScaler can select up to 9 bytes from the target: http.req.url.hostname.set_text _mode(urlencoded).prefix(3)
<text>.SET_TEXT_MODE(URLENCODE D|NOURLENCODED)
<text>.SET_TEXT_MODE(PLUS_AS_S PACE|NO_PLUS_AS_SPACE)
Specifies how to treat the plus character (+). The PLUS_AS_SPACE option replaces
223
Chapter 6
Description a plus character with white space. For example, the text hello+world becomes hello world. The NO_PLUS_AS_SPACE option leaves plus characters as they are.
<text>.SET_TEXT_MODE(BACKSLASH _ENCODED|NO_BACKSLASH_ENCODED)
Specifies whether or not backslash decoding is performed on the text object represented by <text>. If BACKSLASH_ENCODED is specified, the SET_TEXT_MODE operator performs the following operations on the text object: w All occurrences of \XXX will be replaced with the character Y (where XXX represents a number in the octal system and Y represents the ASCII equivalent of XXX). The valid range of octal values for this type of encoding is 0 to 377. For example, the encoded text "http \72//" and "http\072//" will both be decoded to "http://", where the colon (:) is the ASCII equivalent of the octal value 72. w All occurrences of \xHH will be replaced with the character Y (HH represents a number in the hexadecimal system and Y denotes the ASCII equivalent of HH. For example, the encoded text "http \x3a//" will be decoded to "http://", where the colon (:) is the ASCII equivalent of the hexadecimal value 3a. w All occurrences of \\uWWXX will be replaced with the character sequence YZ (Where WW and XX represent two distinct hexadecimal values and Y and Z represent their ASCII equivalents of WW and XX respectively. For example, the encoded text "http%u3a2f/" and "http %u003a//" will both be decoded to
224
Description "http://", where 3a and 2f are two hexadecimal values and the colon (:) and forward slash (/) represent their ASCII equivalents respectively. w All occurrences of "\b", "\n", "\t", "\f", and "\r" are replaced with the corresponding ASCII characters. If NO_BACKSLASH_ENCODED is specified, backslash decoding is not performed on the text object.
Performs the associated undefined action if either the URLENCODED or the BACKSLASH_ENCODED mode is set and bad encoding corresponding to the specified encoding mode is encountered in the text object represented by <text>. If NO_BAD_ENCODE_RAISE_UNDEF is specified, the associated undefined action will not be performed when bad encoding is encountered in the text object represented by<text>.
225
Chapter 6
GET Operation
Description payload and continuing for the number of characters in the <integer> argument. You can apply any text-based operation to this prefix.
CLIENT.TCP.SRCPORT
Returns the ID of the current packet's source port as a number. Returns the ID of the current packet's destination port as a number. Returns the TCP options set by the client. Examples of TCP options are Maximum Segment Size (MSS), Window Scale, Selective Acknowledgements (SACK), and Time Stamp Option. The COUNT, TYPE(<type>), and TYPE_NAME(<m>) operators can be used with this prefix. For the TCP options set by the server, see the SERVER.TCP.OPTIONS prefix. Returns the number of TCP options that the client has set. Returns the value of the TCP option whose type (or option kind) is specified as the argument. The value is returned as a string of bytes in big endian format (or network byte order). Parameters: type - Type value
CLIENT.TCP.DSTPORT
CLIENT.TCP.OPTIONS
CLIENT.TCP.OPTIONS.COUNT
CLIENT.TCP.OPTIONS.TYPE(<type> )
CLIENT.TCP.OPTIONS.TYPE_NAME(< m>)
Returns the value of the TCP option whose enumeration constant is specified as the argument. The enumeration constants that you can pass as the argument are REPEATER, TIMESTAMP, SACK_PERMITTED, WINDOW, and MAXSEG. To specify the TCP option kind instead of these enumeration constants, use CLIENT.TCP.OPTIONS.TYPE(<type>).
226
GET Operation
Description For other TCP options, you must use CLIENT.TCP.OPTIONS.TYPE(<type>). Parameters: m - TCP option enumeration constant
Returns a Boolean TRUE if Repeater TCP options exist. Returns the branch repeater's IPv4 address from the Repeater TCP options. Returns the branch repeater's MAC address from the Repeater TCP options. Returns the DNS domain name. Returns a Boolean TRUE if the domain name matches the <hostname> argument. The comparison is case insensitive. Following is an example: client.udp.dns.domain.eq("www.m ycompany.com")
CLIENT.TCP.REPEATER_OPTION.MAC
CLIENT.UDP.DNS.IS_AAAAREC
Returns a Boolean TRUE if the record type is AAAA. These types of records indicate an IPv6 address in forward lookups. Returns a Boolean TRUE if it is of any record type. Returns a Boolean TRUE if the record is type A. Type A records provide the host address. Returns a Boolean TRUE if the record is of type CNAME. In systems that use multiple names to identify a resource, there is one canonical name and a number of aliases. The CNAME provides the canonical name.
CLIENT.UDP.DNS.IS_ANYREC
CLIENT.UDP.DNS.IS_AREC
CLIENT.UDP.DNS.IS_CNAMEREC
227
Chapter 6
Description Returns a Boolean TRUE if the record is of type MX (mail exchanger). This DNS record describes a priority and a host name. The MX records for the same domain name specify the email servers in the domain and the priority for each server. Returns a Boolean TRUE if the record is of type NS. This is a name server record that includes a host name with an associated A record. This enables locating the domain name that is associated with the NS record. Returns a Boolean TRUE if the record is of type PTR. This is a domain name pointer and is often used to associate a domain name with an IPv4 address. Returns a Boolean TRUE if the record is of type SOA. This is a start of authority record. Returns a Boolean TRUE if the record is of type SRV. This is a more general version of the MX record. Returns the numeric ID of the current packet's UDP destination port. Returns the numeric ID of the current packet's UDP source port. Returns RADIUS data for the current packet. Returns the value for the attribute type specified as the argument. Returns the RADIUS user name. Returns the maximum segment size (MSS) for the current connection as a number.
CLIENT.UDP.DNS.IS_NSREC
CLIENT.UDP.DNS.IS_PTRREC
CLIENT.UDP.DNS.IS_SOAREC
CLIENT.UDP.DNS.IS_SRVREC
CLIENT.UDP.DSTPORT
CLIENT.UDP.SRCPORT
CLIENT.UDP.RADIUS
228
Description Returns the numeric ID of the VLAN through which the current packet entered the NetScaler. Returns the numeric ID of the current packet's destination port. Returns the numeric ID of the current packet's source port. Returns the TCP options set by the server. Examples of TCP options are Maximum Segment Size (MSS), Window Scale, Selective Acknowledgements (SACK), and Time Stamp Option. The COUNT, TYPE(<type>), and TYPE_NAME(<m>) operators can be used with this prefix. For the TCP options set by the client, see the CLIENT.TCP.OPTIONS prefix. Returns the number of TCP options that the server has set. Returns the value of the TCP option whose type (or option kind) is specified as the argument. The value is returned as a string of bytes in big endian format (or network byte order). Parameters: type - Type value
SERVER.TCP.DSTPORT
SERVER.TCP.SRCPORT
SERVER.TCP.OPTIONS
SERVER.TCP.OPTIONS.COUNT
SERVER.TCP.OPTIONS.TYPE(<type> )
SERVER.TCP.OPTIONS.TYPE_NAME(< m>)
Returns the value of the TCP option whose enumeration constant is specified as the argument. The enumeration constants that you can pass as the argument are REPEATER, TIMESTAMP, SACK_PERMITTED, WINDOW, and MAXSEG. To specify the TCP option kind instead of these enumeration constants, use CLIENT.TCP.OPTIONS.TYPE(<type>). For other TCP options, you must use CLIENT.TCP.OPTIONS.TYPE(<type>).
229
Chapter 6
GET Operation
SERVER.VLAN
Operates on the VLAN through which the current packet entered the NetScaler. Returns the numeric ID of the VLAN through which the current packet entered the NetScaler.
SERVER.VLAN.ID
Expressions for Evaluating a DNS Message and Identifying Its Carrier Protocol
You can evaluate DNS requests and responses by using expressions that begin with DNS.REQ and DNS.RES, respectively. You can also identify the transport layer protocol that is being used to send the DNS messages. The following functions return the contents of a DNS query. Table 6-11. Functions that return the contents of a DNS query Function DNS.REQ.QUESTION.DOMAIN Description Return the domain name (the value of the QNAME field) in the question section of the DNS query. The domain name is returned as a text string, which can be passed to EQ(), NE(), and any other functions that work with text. Return the query type (the value of the QTYPE field) in the DNS query. The field indicates the type of resource record (for example, A, NS, or CNAME) for which the name server is being queried. The returned value can be compared to one of the following values by using the EQ() and NE() functions: w A w AAAA w NS 230
DNS.REQ.QUESTION.TYPE
Function
Description w SRV w PTR w CNAME w SOA w MX w ANY Note: You can use only the EQ() and NE() functions with the TYPE function. Example: DNS.REQ.QUESTION.TYPE.EQ(MX)
The following functions return the contents of a DNS response. Table 6-12. Functions that return the contents of a DNS response Function DNS.RES.HEADER.RCODE Description Return the response code (the value of the RCODE field) in the header section of the DNS response. You can use only the EQ() and NE() functions with the RCODE function. Following are the possible values: w NOERROR w FORMERR w SERVFAIL w NXDOMAIN w NOTIMP w REFUSED DNS.RES.QUESTION.DOMAIN Return the domain name (the value of the QNAME field) in the question section of the DNS response. The domain name is returned as a text string, which can be passed to EQ(), NE(), and any other functions that work with text.
231
Chapter 6
Function DNS.RES.QUESTION.TYPE
Description Return the query type (the value of the QTYPE field) in the question section of the DNS response. The field indicates the type of resource record (for example, A, NS, or CNAME) that is contained in the response. The returned value can be compared to one of the following values by using the EQ() and NE() functions: w A w AAAA w NS w SRV w PTR w CNAME w SOA w MX w ANY You can use only the EQ() and NE() functions with the TYPE function. Example: DNS.RES.QUESTION.TYPE.EQ(SOA)
The following functions return the transport layer protocol name. Table 6-13. Functions that return the transport layer protocol name Function DNS.REQ.TRANSPORT Description Return the name of the transport layer protocol that was used to send the DNS query. Possible values returned are TCP and UDP. You can use only the EQ() and NE() functions with the TRANSPORT function. Example: DNS.REQ.TRANSPORT.EQ(TCP)
232
Function DNS.RES.TRANSPORT
Description Return the name of the transport layer protocol that was used for the DNS response. Possible values returned are TCP and UDP. You can use only the EQ() and NE() functions with the TRANSPORT function. Example: DNS.RES.TRANSPORT.EQ(TCP)
233
Chapter 6
XPath Prefix
<text>.XPATH(xpathex)
Operate on an XML file and return a value of data type double. For example, the following expression converts the string 36 (a price value) to a value of data type double if the string is in the first 1000 bytes of the XML file: HTTP.REQ.BODY(1000).XPATH(xp %number(/Book/price)%) Parameters: xpathex - XPath numeric expression
<text>.XPATH(xpathex)
Operate on an XML file and return a nodeset or a string. Node-sets are converted to corresponding strings by using the standard XPath string conversion routine. For example, the following expression selects all the nodes that are enclosed by /Book/creator (a node-set) in the first 1000 bytes of the body: HTTP.REQ.BODY(1000).XPATH(xp%/ Book/creator%) Parameters: xpathex - XPath expression
<text>.XPATH_HTML(xpathex)
Operate on an HTML file and return a text value. For example, the following expression operates on an HTML file and returns the text enclosed in <title></title> tags if the title HTML element is found in the first 1000 bytes: HTTP.REQ.BODY(1000).XPATH_HTML (xp%/html/head/title%) Parameters: xpathex - XPath text expression
234
Description Operate on an HTML file and return a string that contains the entire selected portion of the document, including markup such as including the enclosing element tags. The following expression operates on the HTML file and selects all content within the <title> tag, including markup. HTTP.REQ.BODY(1000).XPATH_HTML _WITH_MARKUP( xp%/html/head/ title%) The portion of the HTML body that is selected by the expression is marked for further processing. Parameters: xpathex - XPath expression
<text>.XPATH_JSON(xpathex)
Operate on a JSON file and return a Boolean value. For example, consider the following JSON file: { "Book":{ "creator":{ "person": { "name":'<name>' } }, "title":'<title>' } } The following expression operates on the JSON file and returns a Boolean TRUE if the JSON file contains a node named creator, whose parent node is Book, in the first 1000 bytes: HTTP.REQ.BODY(1000).XPATH_JSON (xp%boolean(/Book/creator)%) Parameters: xpathex - XPath Boolean expression
<text>.XPATH_JSON(xpathex)
Operate on a JSON file and return a value of data type double. For example, consider the following JSON file:
235
Chapter 6
XPath Prefix
Description { "Book":{ "creator":{ "person": { "name":'<name>' } }, "title":'<title>', "price":"36" } } The following expression operates on the JSON file and converts the string 36 to a value of data type double if the string is present in the first 1000 bytes of the JSON file. HTTP.REQ.BODY(1000).XPATH_JSON (xp%number(/Book/price)%) Parameters: xpathex - XPath numeric expression
<text>.XPATH_JSON(xpathex)
Operate on a JSON file and return a nodeset or a string. Node-sets are converted to corresponding strings by using the standard XPath string conversion routine. For example, consider the following JSON file: { "Book":{ "creator":{ "person": { "name":'<name>' } }, "title":'<title>' } } The following expression selects all the nodes that are enclosed by /Book" (a node-set) in the first 1000 bytes of the body of the JSON file and returns the corresponding string value, which is "<name><title>": HTTP.REQ.BODY(1000).XPATH_JSON (xp%/Book%) Parameters: xpathex - XPath expression
<text>.XPATH_JSON_WITH_MARKUP( xpathex)
Operate on an XML file and return a string that contains the entire portion of the document for the result node, including markup such as including the enclosing element tags. For example, consider the following JSON file:
236
XPath Prefix
Description {"Book":{ "creator":{ "person": { "name":'<name>' } }, "title":'<title>' } } The following expression operates on the JSON file and selects all the nodes that are enclosed by /Book/creator" in the first 1000 bytes of the body, which is creator:{ person:{ name:'<name>' } }. HTTP.REQ.BODY(1000).XPATH_JSON _WITH_MARKUP(xp%/Book/creator %) The portion of the JSON body that is selected by the expression is marked for further processing. Parameters: xpathex - XPath expression
<text>.XPATH_WITH_MARKUP(xpath ex)
Operate on an XML file and return a string that contains the entire portion of the document for the result node, including markup such as including the enclosing element tags. For example, the following expression operates on an XML file and selects all the nodes enclosed by /Book/creator" in the first 1000 bytes of the body. HTTP.REQ.BODY(1000).XPATH_WITH _MARKUP(xp%/Book/creator%) The portion of the JSON body that is selected by the expression is marked for further processing. Parameters: xpathex - XPath expression
Chapter 6
Default Syntax Expressions: Parsing HTTP, TCP, and UDP Data Encryption specification. In the subset, data encryption uses a bulk cipher method (RC4, DES3, AES128, AES192, or AES256), and an RSA public key is used to encrypt the bulk cipher key. Note: If you want to encrypt and decrypt text in a payload, you must use the ENCRYPT and DECRYPT functions. For more information about these functions, see "Encrypting and Decrypting Text". The XML_ENCRYPT() and XML_DECRYPT() functions are not dependent on the encryption/decryption service that is used by the ENCRYPT and DECRYPT commands for text. The cipher method is specified explicitly as an argument to the XML_ENCRYPT() function. The XML_DECRYPT() function obtains the information about the specified cipher method from the <xenc:EncryptedData> element. Following are synopses of the XML encryption and decryption functions: w XML_ENCRYPT(<certKeyName>, <method> [, <flags>]). Returns an <xenc:EncryptedData> element that contains the encrypted input text and the encryption key, which is itself encrypted by using RSA. w XML_DECRYPT(<certKeyName>). Returns the decrypted text from the input <xenc:EncryptedData> element, which includes the cipher method and the RSAencrypted key. Note: The <xenc:EncryptedData> element is defined in the W3C XML Encryption specification. Following are descriptions of the arguments: certKeyName Selects an X.509 certificate with an RSA public key for XML_ENCRYPT() or an RSA private key for XML_DECRYPT(). The certificate key must have been previously created by an add ssl certKey command. method Specifies which cipher method to use for encrypting the XML data. Possible values: RC4, DES3, AES128, AES192, AES256. flags A bitmask specifying the following optional key information (<ds:KeyInfo>) to be included in the <xenc:EncryptedData> element that is generated by XML_ENCRYPT(): w 1 - Include a KeyName element with the certKeyName. The element is <ds:KeyName>. w 2 - Include a KeyValue element with the RSA public key from the certificate. The element is <ds:KeyValue>. w 4 - Include an X509IssuerSerial element with the certificate serial number and issuer DN. The element is <ds:X509IssuserSerial>.
238
Citrix NetScaler Policy Configuration and Reference Guide w 8 - Include an X509SubjectName element with the certificate subject DN. The element is <ds:X509SubjectName>. w 16 - Include an X509Certificate element with the entire certificate. The element is <ds:X509Certificate>.
Chapter 6
Default Syntax Expressions: Parsing HTTP, TCP, and UDP Data The action my-xml-decrypt-action decrypts the first <xenc:EncryptedData> element in the response (XPATH_WITH_MARKUP(xp%//xenc:EncryptedData%)). This requires the prior addition of the xenc XML namespace by use of the following CLI command: add ns xmlnamespace xenc http://www.w3.org/2001/04/xmlenc# The my-xml-decrypt-action action uses the RSA private key in my-certkey to decrypt the encrypted key and then uses the bulk encryption method specified in the element to decrypt the encrypted contents. Finally, the action replaces the encrypted data element with the decrypted content. The rewrite policy my-xml-encrypt-policy applies my-xml-encrypt-action to requests for URLs containing xml-encrypt. The action encrypts the entire response from a service configured on the NetScaler appliance. The rewrite policy my-xml-decrypt-policy applies my-xml-decrypt-action to requests that contain an <xenc:EncryptedData> element ((XPATH(xp%// xenc:EncryptedData%) returns a non-empty string). The action decrypts the encrypted data in requests that are bound for a service configured on the NetScaler appliance.
240
Chapter 7
241
Chapter 7
CLIENT.SSL.CLIENT_CERT.TO_PEM
CLIENT.SSL.CIPHER_EXPORTABLE
CLIENT.SSL.CIPHER_NAME
CLIENT.SSL.IS_SSL
242
Prefix CLIENT.SSL.CLIENT_CERT.PK_SIZE
Description Returns the size of the public key used in the certificate. Returns the version number of the certificate. If the connection is not SSLbased, returns zero (0). Returns the number of bits in the cryptograhic key. Returns 0 if the connection is not SSL-based. Returns a number that represents the SSL protocol version, as follows: w 0. The transaction is not SSL-based. w 0x002. The transaction is SSLv2. w 0x300. The transaction is SSLv3. w 0x301. The transaction is TLSv1.
CLIENT.SSL.CLIENT_CERT.VERSION
CLIENT.SSL.CIPHER_BITS
CLIENT.SSL.VERSION
Note: For expressions related to expiration dates in a certificate, see Expressions for SSL Certificate Dates on page 167.
243
Chapter 7
Default Syntax Expressions: Parsing SSL Certificates Table 7-3. Operations That Can Be Specified with the CLIENT.SSL.CLIENT_CERT Prefix SSL Certificate Operation <certificate >.EXISTS <certificate >.ISSUER Description
Returns the Distinguished Name (DN) of the Issuer in the certificate as a name-value list. An equals sign (=) is the delimiter for the name and the value, and the slash (/) is the delimiter that separates the name-value pairs. Following is an example of the returned DN: /C=US/O=myCompany/OU=www.mycompany.com/ CN=www.mycompany.com/ emailAddress=myuserid@mycompany.com
Returns the Issuer and ignores the empty elements in a namevalue list. For example, consider the following: Cert-Issuer: /c=in/st=kar//l=bangelore // o=mycompany/ou=sales/ / emailAddress=myuserid@mycompany.com The following Rewrite action returns a count of 6 based on the preceding Issuer definition: sh rewrite action insert_ssl_header Name: insert_ssl Operation: insert_http_header Target:Cert-Issuer Value:CLIENT.SSL.CLIENT_CERT.ISSUER.COUNT However, if you change the value to the following, the returned count is 9: CLIENT.SSL.CLIENT_CERT.ISSUER.IGNORE_EMPTY_ELEMEN TS.COUNT
Returns a string that contains the Authority Key Identifier extension of the X.509 V3 certificate. Returns the SerialNumber field of the Authority Key Identifier as a blob.
244
Description
Returns a Boolean TRUE if the certificate contains an Authority Key Identifier extension.
Returns the Issuer Distinguished Name in the certificate as a namevalue list. An equals sign (=) is the delimiter for the name and the value, and the slash (/) is the delimiter that separates the name-value pairs. Following is an example: /C=US/O=myCompany/OU=www.mycompany.com/ CN=www.mycompany.com/ emailAddress=myuserid@mycompany.com
Returns the Issuer Distinguished Name in the certificate as a namevalue list and ignores the empty elements in the list. For example, the following name-value list has an empty element following a=10: a=10;;b=11; ;c=89 The element following b=11 is not considered an empty element.
Returns a string that contains the client certificate policy. Note that this represents a sequence of certificate policies.
Returns a Boolean value to indicate whether the specified key usage extension bit value in the X.509 certificate is set. The string argument specifies which bit is checked. Following are valid arguments: w DIGITAL_SIGNATURE. Returns TRUE if the digital signature bit is set; otherwise, it returns FALSE. w NONREPUDIATION. Returns TRUE if the nonrepudiation bit is set; otherwise, it returns FALSE. w KEYENCIPHERMENT. Returns TRUE if the key encipherment bit is set; otherwise, it returns FALSE.
245
Chapter 7
Description
w DATAENCIPHERMENT. Returns TRUE if the data encipherment bit is set; otherwise, it returns FALSE. w KEYAGREEMENT. Returns TRUE if the key agreement bit is set; otherwise, it returns FALSE. w KEYCERTSIGN. Returns TRUE if the key cert sign bit is set; otherwise, it returns FALSE. w CRLSIGN. Returns TRUE if the CRL bit is set; otherwise, it returns FALSE. w ENCIPHERONLY. Returns TRUE if the encipher only bit is set; otherwise, it returns FALSE. w DECIPHERONLY. Returns TRUE if the decipher only bit is set; otherwise, it returns FALSE. <certificate >.PK_ALGORIT HM <certificate >.PK_SIZE <certificate >.SERIALNUMB ER <certificate >.SIGNATURE_ ALGORITHM <certificate >.SUBJECT Returns the name of the public key algorithm used by the certificate.
Returns the serial number of the client certificate. If this is a nonSSL transaction or there is an error in the certificate, this operation returns an empty string. Returns the name of the cryptographic algorithm used by the CA to sign this certificate.
Returns the Distinguished Name of the Subject as a name-value. An equals sign (=) separates names and values and a slash (/) delimits name-value pairs. Following is an example: /C=US/O=myCompany/OU=www.mycompany.com/ CN=www.mycompany.com/ emailAddress=myuserid@mycompany.com
<certificate >.SUBJECT.IG
Returns the Subject as a name-value list, but ignores the empty elements in the list. For example, consider the following:
246
Description
Cert-Issuer: /c=in/st=kar//l=bangelore // o=mycompany/ou=sales/ / emailAddress=myuserid@mycompany.com The following Rewrite action returns a count of 6 based on the preceding Issuer definition: sh rewrite action insert_ssl_header Name: insert_ssl Operation: insert_http_header Target:Cert-Issuer Value:CLIENT.SSL.CLIENT_CERT.ISSUER.COUNT However, if you change the value to the following, the returned count is 9: CLIENT.SSL.CLIENT_CERT.ISSUER.IGNORE_EMPTY_ELEMEN TS.COUNT
Returns the Subject KeyID of the client certificate. If there is no Subject KeyID, this operation returns a zero-length text object.
247
Chapter 7
248
Chapter 8
249
Chapter 8
250
Prefix CLIENT.IP.DST
Description Returns the destination IP of the current packet as an IP address or as a number. Returns the source IP of the current packet as an IP address or as a number. Returns the destination IP of the current packet as an IP address or as a number.
SERVER.IP.SRC
SERVER.IP.DST
251
Chapter 8
Prefix
<ip address>.SUBNET(<n>)
Returns the IP address after applying the subnet mask specified as the argument. The subnet mask can take values between 0 and 32. For example: CLIENT.IP.SRC.SUBNET(24) returns 192.168.1.0 if the IP address represented by the prefix is 192.168.1.[0-255].
<ip address>.IS_IPV6
Returns a Boolean TRUE if this is an Internet Protocol version 6 (IPv6) host for the client or server. Following is an example: client.ip.src.is_ipv6
<ip address>.MATCHES(<hostname>)
Returns a Boolean TRUE if the IP address for the host specified in <hostname> matches the current IP address. The <hostname> cannot exceed 255 characters. Returns a Boolean TRUE if the location of the IP address matches the <location> argument. The Location string can take the following form: qual1.qual2.qual3.qual4.qual5.qual6, for example: NorthAmeria.CA.* Following is an example: client.ip.src.matches_location (\"Europe.GB.17.London.*.*\")
Citrix NetScaler Policy Configuration and Reference Guide Example 1: 9901:0ab1:22a2:88a3:3333:4a4b:5555:6666 Example 2: http://[9901:0ab1:22a2:88a3:3333:4a4b:5555:6666]/ Example 3: https://[9901:0ab1:22a2:88a3:3333:4a4b:5555:6666]:8080/ In Example 3, the brackets separate the IP address from the port number (8080). Note that you can only use the '+' operator to combine IPv6 expressions with other expressions. The output is a concatenation of the string values that are returned from the individual expressions. You cannot use any other arithmetic operator with an IPv6 expression. The following syntax is an example: client.ipv6.src + server.ip.dst For example, if the client source IPv6 address is ABCD:1234::ABCD, and the server destination IPv4 address is 10.100.10.100, the preceding expression returns "ABCD: 1234::ABCD10.100.10.100". Note that when the NetScaler appliance receives an IPv6 packet, it assigns a temporary IPv4 address from an unused IPv4 address range and changes the source address of the packet to this temporary address. At response time, the outgoing packet's source address is replaced with the original IPv6 address. Note: You can combine an IPv6 expression with any other expression except an expression that produces a Boolean result.
CLIENT.IPV6.DST
253
Chapter 8
Prefix CLIENT.IPV6.SRC
Description Returns the IPv6 address in the source field of the IP header. Following are examples: client.ipv6.src.in_subnet(2007 ::2008/64) client.ipv6.src.get1.le(2008)
SERVER.IPV6
Operates on the IPv6 address in with the current packet. Returns the IPv6 address in the destination field of the IP header. Returns the IPv6 address in the source field of the IP header. Following are examples: server.ipv6.src.in_subnet(2007 ::2008/64) server.ipv6.src.get1.le(2008)
SERVER.IPV6.DST
SERVER.IPV6.SRC
254
IPv6 Operation
Description The following example expressions retrieve segments from the ipv6 address 1000:1001:CD10:0000:0000:89AB: 4567:CDEF: w client.ipv6.dst.get5 extracts 0000, which is the fifth set of bits in the address. w client.ipv6.dst.get6 extracts 89AB. w client.ipv6.dst.get7 extracts 4567. You can perform numeric operations on these segments. Note that you cannot perform numeric operations when you retrieve an entire IPv6 address. This is because expressions that return an entire IPv6 address, such as CLIENT.IPV6.SRC, return the address in text format.
<ipv6>.IN_SUBNET(<subnet>)
Returns a Boolean TRUE if the IPv6 address value is in the subnet specified by the <subnet> argument. Following is an example: client.ipv6.dst.eq(1000:1001:C D10:0000:0000:89AB:4567:CDEF/ 60)
<ipv6>.IS_IPV4
Returns a Boolean TRUE if this is an IPv4 client, and returns a Boolean FALSE if it is not. Returns the IPv6 address after applying the subnet mask specified as the argument. The subnet mask can take values between 0 and 128. For example: CLIENT.IPV6.SRC.SUBNET(24)
<ipv6>.SUBNET(<n>)
255
Chapter 8
client.ether.srcmac
256
client.interface.txthroughput
client.interface.rxtxthroughpu t
server.interface.rxthroughput
server.interface.txthroughput
server.interface.rxtxthroughpu t
server.vlan.id
client.vlan.id
257
Chapter 8
258
Chapter 9
259
Chapter 9
260
Chapter 10
261
Chapter 10
262
Citrix NetScaler Policy Configuration and Reference Guide CP1250_GENERAL_CI LATIN2_CROATIAN_CI CP1257_LITHUANIAN_CI LATIN5_TURKISH_CI LATIN1_GERMAN2_CI ARMSCII8_GENERAL_CI UTF8_GENERAL_CI CP1250_CZECH_CS CP866_GENERAL_CI KEYBCS2_GENERAL_CI MACCE_GENERAL_CI MACROMAN_GENERAL_CI CP852_GENERAL_CI LATIN7_GENERAL_CI LATIN7_GENERAL_CS MACCE_BIN CP1250_CROATIAN_CI LATIN1_BIN LATIN1_GENERAL_CI LATIN1_GENERAL_CS CP1251_BIN CP1251_GENERAL_CI CP1251_GENERAL_CS MACROMAN_BIN CP1256_GENERAL_CI CP1257_BIN CP1257_GENERAL_CI ARMSCII8_BIN ASCII_BIN CP1250_BIN CP1256_BIN CP866_BIN 263
Chapter 10
Default Syntax Expressions: DataStream DEC8_BIN GREEK_BIN HEBREW_BIN HP8_BIN KEYBCS2_BIN KOI8R_BIN KOI8U_BIN LATIN2_BIN LATIN5_BIN LATIN7_BIN CP850_BIN CP852_BIN SWE7_BIN UTF8_BIN GEOSTD8_GENERAL_CI GEOSTD8_BIN LATIN1_SPANISH_CI UTF8_UNICODE_CI UTF8_ICELANDIC_CI UTF8_LATVIAN_CI UTF8_ROMANIAN_CI UTF8_SLOVENIAN_CI UTF8_POLISH_CI UTF8_ESTONIAN_CI UTF8_SPANISH_CI UTF8_SWEDISH_CI UTF8_TURKISH_CI UTF8_CZECH_CI UTF8_DANISH_CI UTF8_LITHUANIAN_CI UTF8_SLOVAK_CI UTF8_SPANISH2_CI
264
Citrix NetScaler Policy Configuration and Reference Guide UTF8_ROMAN_CI UTF8_PERSIAN_CI UTF8_ESPERANTO_CI UTF8_HUNGARIAN_CI INVAL_CHARSET w MYSQL.CLIENT.DATABASE. Returns the name of the database specified in the authentication packet that the client sends to the database server. This is the databasename attribute. w MYSQL.CLIENT.USER. Returns the user name (in the authentication packet) with which the client is attempting to connect to the database. This is the user attribute. w MYSQL.REQ. Operates on a MySQL request. w MYSQL.REQ.COMMAND. Identifies the enumeration constant assigned to the type of command in the request. The EQ(<m>) and NE(<m>) operators, which return Boolean values to indicate the result of a comparison, are used with this prefix. Following are the enumeration constant values: SLEEP QUIT INIT_DB QUERY FIELD_LIST CREATE_DB DROP_DB REFRESH SHUTDOWN STATISTICS PROCESS_INFO CONNECT PROCESS_KILL DEBUG PING TIME DELAYED_INSERT CHANGE_USER BINLOG_DUMP 265
Chapter 10
Default Syntax Expressions: DataStream TABLE_DUMP CONNECT_OUT REGISTER_SLAVE STMT_PREPARE STMT_EXECUTE STMT_SEND_LONG_DATA STMT_CLOSE STMT_RESET SET_OPTION STMT_FETCH w MYSQL.REQ.QUERY. Identifies the query in the MySQL request. w MYSQL.REQ.QUERY.COMMAND. Returns the first keyword in the MySQL query. w MYSQL.REQ.QUERY.SIZE. Returns the size of the request query in integer format. The SIZE method is similar to the CONTENT_LENGTH method that returns the length of an HTTP request or response. w MYSQL.REQ.QUERY.TEXT. Returns a string covering the entire query. w MYSQL.REQ.QUERY.TEXT(<n>). Returns the first n bytes of the MySQL query as a string. This is similar to HTTP.BODY(<n>). Parameters: n - Number of bytes to be returned w MYSQL.RES. Operates on a MySQL response. w MYSQL.RES.ATLEAST_ROWS_COUNT(<i>). Checks whether the response has at least i number of rows and returns a Boolean TRUE or FALSE to indicate the result. Parameters: i - Number of rows w MYSQL.RES.ERROR. Identifies the MySQL error object. The error object includes the error number and the error message. w MYSQL.RES.ERROR.MESSAGE. Returns the error message that is retrieved from the server's error response. w MYSQL.RES.ERROR.NUM. Returns the error number that is retrieved from the server's error response. w MYSQL.RES.ERROR.SQLSTATE. Returns the value of the SQLSTATE field in the server's error response. The MySQL server translates error number values to SQLSTATE values.
266
Citrix NetScaler Policy Configuration and Reference Guide w MYSQL.RES.FIELD(<i>). Identifies the packet that corresponds to the ith individual field in the server's response. Each field packet describes the properties of the associated column. The packet count (i) begins at 0. Parameters: i - Packet number w MYSQL.RES.FIELD(<i>).CATALOG. Returns the catalog property of the field packet. w MYSQL.RES.FIELD(<i>).CHAR_SET. Returns the character set of the column. The EQ(<m>) and NE(<m>) operators, which return Boolean values to indicate the result of a comparison, are used with this prefix. w MYSQL.RES.FIELD(<i>).DATATYPE. Returns an enumeration constant that represents the data type of the column. This is the type (also called enum_field_type) attribute of the column. The EQ(<m>) and NE(<m>) operators, which return Boolean values to indicate the result of a comparison, are used with this prefix. The possible values for the various data types are: DECIMAL TINY SHORT LONG FLOAT DOUBLE NULL TIMESTAMP LONGLONG INT24 DATE TIME DATETIME YEAR NEWDATE VARCHAR (new in MySQL 5.0) BIT (new in MySQL 5.0) NEWDECIMAL (new in MySQL 5.0) ENUM SET 267
Chapter 10
Default Syntax Expressions: DataStream TINY_BLOB MEDIUM_BLOB LONG_BLOB BLOB VAR_STRING STRING GEOMETRY w MYSQL.RES.FIELD(<i>).DB. Returns the database identifier (db) attribute of the field packet. w MYSQL.RES.FIELD(<i>).DECIMALS. Returns the number of positions after the decimal point if the type is DECIMAL or NUMERIC. This is the decimals attribute of the field packet. w MYSQL.RES.FIELD(<i>).FLAGS. Returns the flags property of the field packet. Following are the possible hexadecimal flag values: 0001: NOT_NULL_FLAG 0002: PRI_KEY_FLAG 0004: UNIQUE_KEY_FLAG 0008: MULTIPLE_KEY_FLAG 0010: BLOB_FLAG 0020: UNSIGNED_FLAG 0040: ZEROFILL_FLAG 0080: BINARY_FLAG 0100: ENUM_FLAG 0200: AUTO_INCREMENT_FLAG 0400: TIMESTAMP_FLAG 0800: SET_FLAG w MYSQL.RES.FIELD(<i>).LENGTH. Returns the length of the column. This is the value of the length attribute of the field packet. The value that is returned might be larger than the actual value. For example, an instance of a VARCHAR(2) column might return a value of 2 even when it contains only one character. w MYSQL.RES.FIELD(<i>).NAME. Returns the column identifier (the name after the AS clause, if any). This is the name attribute of the field packet. w MYSQL.RES.FIELD(<i>).ORIGINAL_NAME. Returns the original column identifier (before the AS clause, if any). This is the org_name attribute of the field packet.
268
Citrix NetScaler Policy Configuration and Reference Guide w MYSQL.RES.FIELD(<i>).ORIGINAL_TABLE. Returns the original table identifier of the column (before the AS clause, if any). This is the org_table attribute of the field packet. w MYSQL.RES.FIELD(<i>).TABLE. Returns the table identifier of the column (after the AS clause, if any). This is the table attribute of the field packet. w MYSQL.RES.FIELDS_COUNT. Returns the number of field packets in the response (the field_count attribute of the OK packet). w MYSQL.RES.OK. Identifies the OK packet sent by the database server. w MYSQL.RES.OK.AFFECTED_ROWS. Returns the number of rows affected by an INSERT, UPDATE, or DELETE query. This is the value of the affected_rows attribute of the OK packet. w MYSQL.RES.OK.INSERT_ID. Identifies the unique_id attribute of the OK packet. If an auto-increment identity is not generated by the current MySQL statement or query, the value of unique_id, and hence the value returned by the expression, is 0. w MYSQL.RES.OK.MESSAGE. Returns the message property of the OK packet. w MYSQL.RES.OK.STATUS. Identifies the bit string in the server_status attribute of the OK packet. Clients can use the server status to check whether the current command is a part of a running transaction. The bits in the server_status bit string correspond to the following fields (in the given order): IN TRANSACTION AUTO_COMMIT MORE RESULTS MULTI QUERY BAD INDEX USED NO INDEX USED CURSOR EXISTS LAST ROW SEEN DATABASE DROPPED NO BACKSLASH ESCAPES w MYSQL.RES.OK.WARNING_COUNT. Returns the warning_count attribute of the OK packet. w MYSQL.RES.ROW(<i>). Identifies the packet that corresponds to the ith individual row in the database server's response. Parameters: i - Row number
269
Chapter 10
Default Syntax Expressions: DataStream w MYSQL.RES.ROW(<i>).DOUBLE_ELEM(<j>). Checks whether the jth column of the ith row of the table is NULL. Following C conventions, both indexes i and j start from 0. Therefore, row i and column j are actually the (i+1)th row and the (j +1)th column, respectively. Parameters: i - Row number j - Column number w MYSQL.RES.ROW(<i>).IS_NULL_ELEM(j). Checks whether the jth column of the ith row of the table is NULL. Following C conventions, both indexes i and j start from 0. Therefore, row i and column j are actually the (i+1)th row and the (j+1)th column, respectively. Parameters: i - Row number j - Column number w MYSQL.RES.ROW(<i>).NUM_ELEM(<j>). Returns an integer value from the jth column of the ith row of the table. Following C conventions, both indexes i and j start from 0. Therefore, row i and column j are actually the (i+1)th row and the (j +1)th column, respectively. Parameters: i - Row number j - Column number w MYSQL.RES.ROW(<i>).TEXT_ELEM(j). Returns a string from the jth column of the ith row of the table. Following C conventions, both indexes i and j start from 0. Therefore, row i and column j are actually the (i+1)th row and the (j+1)th column, respectively. Parameters: i - Row number j - Column number w MYSQL.RES.TYPE. Returns an enumeration constant for the response type. Its values can be ERROR, OK, and RESULT_SET. The EQ(<m>) and NE(<m>) operators, which return Boolean values to indicate the result of a comparison, are used with this prefix.
Citrix NetScaler Policy Configuration and Reference Guide with MSSQL.CLIENT and MSSQL.REQ) in policies to make request switching decisions at the content switching virtual server bind point and the response-based expressions (expressions that begin with MSSQL.RES) to evaluate server responses to userconfigured health monitors. Table 10-1. Expressions for Evaluating Microsoft SQL Server Connections Expression MSSQL.CLIENT.CAPABILITIES Description Returns the OptionFlags1, OptionFlags2, OptionFlags3, and TypeFlags fields of the LOGIN7 authentication packet, in that order, as a 4-byte integer. Each field is 1 byte long and specifies a set of client capabilities. Returns the name of the client database. The value returned is of type text. Returns the user name with which the client authenticated. The value returned is of type text. Returns an enumeration constant that identifies the type of command in the request sent to a Microsoft SQL Server database server. The value returned is of type text. Examples of the values of the enumeration constant are QUERY, RESPONSE, RPC, and ATTENTION. The EQ(<m>) and NE(<m>) operators, which return Boolean values to indicate the result of a comparison, are used with this expression. MSSQL.REQ.QUERY.COMMAND Returns the first keyword in the SQL query. The value returned is of type text. Returns the size of the SQL query in the request. The value returned is a number. Returns the entire SQL query as a string. The value returned is of type text.
MSSQL.CLIENT.DATABASE
MSSQL.CLIENT.USER
MSSQL.REQ.COMMAND
MSSQL.REQ.QUERY.SIZE MSSQL.REQ.QUERY.TEXT
271
Chapter 10
Expression MSSQL.REQ.QUERY.TEXT(<n>)
Description Returns the first n bytes of the SQL query. The value returned is of type text. Parameters: n - Number of bytes
MSSQL.REQ.RPC.NAME
Returns the name of the procedure that is being called in a remote procedure call (RPC) request. The name is returned as a string. Returns a Boolean value that indicates whether the remote procedure call (RPC) request contains a procedure ID or an RPC name. A return value of TRUE indicates that the request contains a procedure ID and a return value of FALSE indicates that the request contains an RPC name. Returns the procedure ID of the remote procedure call (RPC) request as an integer. Checks whether the response has at least i number of rows. The value returned is a Boolean TRUE or FALSE value. Parameters: i - Number of rows
MSSQL.REQ.RPC.IS_PROCID
MSSQL.REQ.RPC.PROCID
MSSQL.RES.ATLEAST_ROWS_COUNT(i )
MSSQL.RES.DONE.ROWCOUNT
Returns a count of the number of rows affected by an INSERT, UPDATE, or DELETE query. The value returned is of type unsigned long. Returns the status field from the DONE token sent by a Microsoft SQL Server database server. The value returned is a number. Returns the error message from the ERROR token sent by a Microsoft SQL
MSSQL.RES.DONE.STATUS
MSSQL.RES.ERROR.MESSAGE
272
Expression
Description Server database server. This is the value of the MsgText field in the ERROR token. The value returned is of type text.
MSSQL.RES.ERROR.NUM
Returns the error number from the ERROR token sent by a Microsoft SQL Server database server. This is the value of the Number field in the ERROR token. The value returned is a number. Returns the error state from the ERROR token sent by a Microsoft SQL Server database server. This is the value of the State field in the ERROR token. The value returned is a number. Returns the data type of the ith field in the server response. The EQ(<m>) and NE(<m>) functions, which return Boolean values to indicate the result of a comparison, are used with this prefix. For example, the following expression returns a Boolean TRUE if the DATATYPE function returns a value of datetime for the third field in the response: MSSQL.RES.FIELD(<2>).DATATYPE. EQ(datetime) Parameters: i - Row number
MSSQL.RES.ERROR.STATE
MSSQL.RES.FIELD(<i>).DATATYPE
MSSQL.RES.FIELD(<i>).LENGTH
Returns the maximum possible length of the ith field in the server response. The value returned is a number. Parameters: i - Row number
MSSQL.RES.FIELD(<i>).NAME
Returns the name of the ith field in the server response. The value returned is of type text.
273
Chapter 10
Expression
MSSQL.RES.ROW(<i>).DOUBLE_ELEM (<j>)
Returns a value of type double from the jth column of the ith row of the table. If the value is not a double value, an UNDEF condition is raised. Following C conventions, both indexes i and j start from 0 (zero). Therefore, row i and column j are actually the (i + 1)th row and the (j + 1)th column, respectively. Parameters: i - Row number j - Column number
MSSQL.RES.ROW(<i>).NUM_ELEM(j)
Returns an integer value from the jth column of ith row of the table. If the value is not an integer value, an UNDEF condition is raised. Following C conventions, both indexes i and j start from 0 (zero). Therefore, row i and column j are actually the (i + 1)th row and the (j + 1)th column, respectively. Parameters: i - Row number j - Column number
MSSQL.RES.ROW(<i>).IS_NULL_ELE M(j)
Checks whether the jth column of the ith row of the table is NULL and returns a Boolean TRUE or FALSE to indicate the result. Following C conventions, both indexes i and j start from 0 (zero). Therefore, row i and column j are actually the (i + 1)th row and the (j + 1)th column, respectively. Parameters:
274
Expression
MSSQL.RES.ROW(<i>).TEXT_ELEM(j )
Returns a text string from the jth column of ith row of the table. Following C conventions, both indexes i and j start from 0 (zero). Therefore, row i and column j are actually the (i + 1)th row and the (j + 1)th column, respectively. Parameters: i - Row number j - Column number
MSSQL.RES.TYPE
Returns an enumeration constant that identifies the response type. Following are the possible return values: w ERROR w OK w RESULT_SET The EQ(<m>) and NE(<m>) operators, which return Boolean values to indicate the result of a comparison, are used with this expression.
275
Chapter 10
276
Chapter 11
Typecasting Data
You can extract data of one type (for example, text or an integer) from requests and responses and transform it to data of another type. For example, you can extract a string and transform the string to time format. You can also extract a string from an HTTP request body and treat it like an HTTP header or extract a value from one type of request header and insert it in a response header of a different type. After typecasting the data, you can apply any operation that is appropriate for the new data type. For example, if you typecast text to an HTTP header, you can apply any operation that is applicable to HTTP headers to the returned value. The following table describes various typecasting operations. Table 11-1. Typecasting Functions Function <text>.TYPECAS T_LIST_T(<sepa rator>) Description Treats the text in an HTTP request or response body as a list whose elements are delimited by the character in the <separator> argument. Index values in the list that is created start with zero (0). Text mode settings have no effect on the separator. For example, even if you set the text mode to IGNORECASE, and the separator is the letter p, an uppercase P is not treated as a separator. The following example creates a Rewrite action that constructs a list from an HTTP request body and extracts the fourth item in the list: add rewrite action myreplace_action REPLACE 'http.req.body(100)' 'http.req.body(100).typecast
277
Chapter 11
Typecasting Data
Function
Description _list_t('?').get(4)' set rewrite policy myreplace_policy -action myreplace_action This policy returns the string fourth item from the following request: GET?first item?second item? third item?fourth item? The following example extracts the fourth-from-last item from the list. add rewrite action myreplace_action1 REPLACE 'http.req.body(100)' 'http.req.body(100).typecast _list_t('?').get_reverse(4)' set rewrite policy myreplace_policy1 -action myreplace_action1 This policy returns the string first item from the following request: GET?first item?second item? third item?fourth item.
Treats the text as a name-value list. The <separator> argument identifies the character and separates the name and the value. The <delimiter> argument identifies the character that separates each name-value pair. The <quote> character is required when typecasting text into a namevalue list that supports quoted strings. Any delimiters that appear within the quoted string are ignored. The text mode has no effect on the delimiters. For example, if the current text mode is IGNORECASE and you specify p as the delimiter, an
278
Function
Description uppercase P is not treated as a delimiter. For example, the following policy counts the number of name-value pairs and inserts the result in a header named name-value-count: add rewrite action mycount_action insert_http_header namevalue-count 'http.req.header("Cookie").t ypecast_nvlist_t('=',';').co unt' set rewrite policy mycount_policy -action mycount_action This policy can extract a count of arguments in Cookie headers and insert the count in a name-valuecount header: Cookie: name=name1; rank=rank1
<text>.TYPECAS T_TIME_T
Treats the designated text as a date string. The following formats are supported: w RFC822: Sun, 06 Nov 1994 08:49:37 GMT w RFC850: Sunday, 06-Nov-94 08:49:37 GMT w ASCII TIME: Sun Nov 6 08:49:37 1994 w HTTP Set-Cookie Expiry date: Sun, 06-Nov-1994 08:49:37 GMT For example, the following policy converts the string to a time value and then extracts the day. This policy matches all requests that have a day value lesser than or equal to 10. Add rewrite policy 279
Chapter 11
Typecasting Data
Function
Description mytime_policy "http.req.body(100) .typecast_time_t.day.le(10)" mytime_action bind rewrite global mytime_policy 100
Treats a numeric string as an IP address. For example, the following policy matches HTTP requests that contains Cookie headers with a value of: 12.34.56.78\r\n. set rewrite policy ip_check_policy -rule 'http.req.cookie .value("ip").typecast_ip_add ress_t.eq(12.34.56.78)' bind rewrite global ip_check_policy 200 -type req_default
Treats a string as an IPv6 address in the following format: 0000:0000:CD00:0000:0000:00AB: 0000:CDEF Treats the designated text as the URL in the first line of an HTTP request header. The supported format is [<protocol>:// <hostname>]<path>?<query>, and the text mode is set to URLENCODED by default. For example, the following policy replaces a URL-encoded part of a string in an HTTP header named Test. add rewrite action replace_header_string replace "http.req.header(\"Test
280
Function
Description \").typecast_http_url_t.path .before_str(\"123\").after_s tr(\"ABC\")" "\"string\"" add rewrite policy rewrite_test_header_policy true replace_header_string bind rewrite global rewrite_test_header_policy 1 END -type res_override Consider the following header: Test: ABC%12123\r\n This policy would replace the preceding header with the value ABC %string123\r\n.
Provides operations for parsing an HTTP host name as it appears in HTTP data. The format for a host name is abc.def.com:8080. Converts text to an HTTP method. For example, the following policy matches any HTTP request that contains a Host header with a value equal to POST: Add rewrite policy method_policy "http.req.header(\"Host\") .typecast_http_method_t.eq(P OST)" act1
Enables the designated text to be parsed like a DNS domain name in the format ab.def.com. Converts the designated text to a multi-line HTTP header that you specify in a <name> argument.
281
Chapter 11
Typecasting Data
Function
Description For example, the following expression converts MyHeader to InHeader: http.req.header("MyHeader"). typcast_http_header_t("InHea der") Typically, text operations that you specify in this type of expression apply to only the last line of this header, with some exceptions. For example, the CONTAINS operation operates on values in all the lines in instances of this header type.
<text>.TYPECAS T_COOKIE_T
Treats the designated text as an HTTP cookie as it appears in a Set-Cookie or Set-Cookie2 header. You can apply name-value list operations as well as text operations to the designated text. For example, you can designate equals (=) as the name-value delimiter and the semicolon (;) as the list element delimiter. If you apply name-value list operations, the list is parsed as if IGNORE_EMPTY_ELEMENTS were in effect. Each cookie begins with a cookiename=cookie-value pair, optionally followed by attribute-value pairs that are separated by a semicolon, as follows: cookie1=value1;version=n.n;v alue;domain=value;path=value If the same attribute appears more than once in a cookie, the value for the first instance of the attribute is returned.
<number>.TYPEC AST_DOUBLE_AT
282
Function <number>.TYPEC AST_IP_ADDRESS _AT <number>.TYPEC AST_TIME_AT <number>.TYPEC AST_TIME_AT.BE TWEEN(<time1>, <time2>)
Returns a Boolean value (TRUE or FALSE) that indicates whether the time value designated by <number> is between the lower and upper time value arguments <time1> and <time2>. The following are prerequisites for this function: w Both the lower and upper time arguments must be fully specified. For example, GMT 1995 Jan is fully specified. But GMT Jan, GMT 1995 20 and GMT Jan Mon_2 are not fully specified. w Both arguments must be either GMT or Local. w The day of the week must not be present in either argument. However, the day of the month can be specified as the first, second, third, or fourth weekday of the month (example Wed_3 is the third Wednesday of the month). w The upper time argument, <time2>, must be bigger than the lower time argument, <time1>. The following examples assume that the current time value is GMT 2005 May 1 10h 15m 30s and that the day is the first Sunday of the month of May in 2005. The result of the evaluation is given after each example. BETWEEN(GMT 2004, GMT 2006): TRUE BETWEEN(GMT 2004 Jan, GMT 2006 Nov): TRUE 283
Chapter 11
Typecasting Data
Function
Description BETWEEN(GMT 2004 Jan, GMT 2006): TRUE BETWEEN(GMT 2005 May Sun_1, GMT 2005 May Sun_3): TRUE BETWEEN(GMT 2005 May 1, GMT May 2005 1): TRUE BETWEEN(LOCAL 2005 May 1, LOCAL May 2005 1): The result depends on the NetScaler system's timezone. Parameters: <time1> - Lower time value <time2> - Upper time value
<number>.TYPEC AST_TIME_AT.DA Y
Extracts the day of the month from the current system time and returns the value as a number that corresponds to the day of the month. The returned value ranges from 1 to 31. Returns a Boolean value (TRUE or FALSE) that indicates whether the time value designated by <number> is equal to the time value argument <t>. The following examples assume that the current time value is GMT 2005 May 1 10h 15m 30s and that the day is the 1st Sunday of the month of May in 2005. The result of the evaluation is given after each example. EQ(GMT 2005): TRUE EQ(GMT 2005 Dec): FALSE EQ(Local 2005 May): TRUE or FALSE, depending on the time zone. EQ(GMT 10h): TRUE EQ(GMT 10h 30s): TRUE EQ(GMT May 10h): TRUE EQ(GMT Sun): TRUE EQ(GMT May Sun_1): TRUE Parameters:
284
Function
Returns a Boolean value (TRUE or FALSE) that indicates whether the time value designated by <number> is greater than or equal to the time value argument <t>. The following examples assume that the current time value is GMT 2005 May 1 10h 15m 30s and that the day is the 1st Sunday of the month of May in 2005. The result of the evaluation is given after each example. GE(GMT 2004): TRUE GE(GMT 2005 Jan): TRUE GE(Local 2005 May): TRUE or FALSE, depending on the time zone. GE(GMT 8h): TRUE GE(GMT 30m): FALSE GE(GMT May 10h): TRUE GE(GMT May 10h 0m): TRUE GE(GMT Sun): TRUE GE(GMT May Sun_1): TRUE Parameters: <t> - Time
Returns a Boolean value (TRUE or FALSE) that indicates whether the time value designated by <number> is greater than the time value argument <t>. The following examples assume that the current time value is GMT 2005 May 1 10h 15m 30s and that the day is the 1st Sunday of the month of May in 2005. The result of the evaluation is given after each example. GT(GMT 2004): TRUE GT(GMT 2005 Jan): TRUE GT(Local 2005 May): TRUE or FALSE, depending on the time
285
Chapter 11
Typecasting Data
Function
Description zone. GT(GMT GT(GMT GT(GMT GT(GMT GT(GMT GT(GMT 8h): TRUE 30m): FALSE May 10h): FALSE May 10h 0m): TRUE Sun): FALSE May Sun_1): FALSE
Parameters: <t> - Time <number>.TYPEC AST_TIME_AT.HO URS Extracts the hour from the current system time and returns the corresponding value as an integer that can range from 0 to 23. Returns a Boolean value (TRUE or FALSE) that indicates whether the time value designated by <number> is lesser than or equal to the time value argument <t>. The following examples assume that the current time value is GMT 2005 May 1 10h 15m 30s and that the day is the 1st Sunday of the month of May in 2005. The result of the evaluation is given after each example. LE(GMT 2006): TRUE LE(GMT 2005 Dec): TRUE LE(Local 2005 May): TRUE or FALSE, depending on the time zone. LE(GMT 8h): FALSE LE(GMT 30m): TRUE LE(GMT May 10h): TRUE LE(GMT Jun 11h): TRUE LE(GMT Wed): TRUE LE(GMT May Sun_1): TRUE Parameters: <t> - Time <number>.TYPEC AST_TIME_AT.LT (<t>) Returns a Boolean value (TRUE or FALSE) that indicates whether the time value designated by <number> is
286
Function
Description lesser than the time value argument <t>. The following examples assume that the current time value is GMT 2005 May 1 10h 15m 30s and that the day is the 1st Sunday of the month of May in 2005. The result of the evaluation is given after each example. LT(GMT 2006): TRUE LT(GMT 2005 Dec): TRUE LT(Local 2005 May): TRUE or FALSE, depending on the time zone. LT(GMT 8h): FALSE LT(GMT 30m): TRUE LT(GMT May 10h): FALSE LT(GMT Jun 11h): TRUE LT(GMT Wed): TRUE LT(GMT May Sun_1): FALSE Parameters: <t> - Time
Extracts the minute from the current system time and returns the value as an integer that can range from 0 to 59. Extracts the month from the current system time and returns the value as an integer that can range from 1 (January) to 12 (December). Calculates the number of seconds that have elapsed after the most recent reboot or the number of seconds to the next scheduled reboot, depending on which is closer to the current time, and returns an integer. If the closest boot time is in the past, the integer is negative. If the closest boot time is in the future (scheduled reboot time), the integer is positive.
287
Chapter 11
Typecasting Data
Description Calculates the number of seconds between the current system time and the specified time, and returns the value as an integer. If the designated time is in the past, the integer is negative. If it is in the future, the integer is positive. Extracts the seconds from the current system time and returns the value as an integer that can range from 0 to 59. Returns an integer that corresponds to the day of the week; 0 for Sunday and 6 for Saturday. Returns a Boolean value (TRUE or FALSE) that indicates whether the time value designated by <number> lies within all the ranges defined by lower and upper time value arguments <time1> and <time2>. If an element of time such as the day or the hour is left unspecified in the lower argument, <time1>, then it is assumed to have the lowest value possible for its range. If an element is left unspecified in the upper argument , <time2>, then it is assumed to have the highest value possible for its range. If the year is specified in one of the arguments, then it must be specified in the other argument as well. Following are the ranges for different elements of time: w month: 1-12 w day: 1-31 w weekday: 0-6 w hour: 0-23 w minutes: 0-59
<number>.TYPEC AST_TIME_AT.SE CONDS <number>.TYPEC AST_TIME_AT.WE EKDAY <number>.TYPEC AST_TIME_AT.WI THIN(<time1>, <time2>)
288
Function
Description w seconds: 0-59. Each element of time in the lower time value argument defines a range in combination with the corresponding element in the upper time value argument. For the result to be TRUE, each element of time in the time value designated by <number> must lie in the corresponding range specified by the lower and upper arguments. The following examples assume that the current time value is GMT 2005 May 10 10h 15m 30s.and that the day is the second Tuesday of the month. The result of the evaluation is given after each example. WITHIN(GMT 2004, GMT 2006): TRUE WITHIN(GMT 2004 Jan, GMT 2006 Mar): FALSE (May doesn't fall in the Jan-Mar range.) WITHIN(GMT Feb, GMT): TRUE (May falls in the Feb-Dec range.) WITHIN(GMT Sun_1, GMT Sun_3): TRUE (2nd Tuesday lies within 1st Sunday and the 3rd Sunday.) WITHIN(GMT 2005 May 1 10h, GMT May 2005 1 17h): TRUE WITHIN(LOCAL 2005 May 1, LOCAL May 2005 1): The result depends on the NetScaler system's timezone. Parameters: <time1> - Lower time value <time2> - Upper time value
289
Chapter 11
Typecasting Data
Description Extracts the year from the current system time and returns the value as a four-digit integer. Casts numeric string data to a signed 32-bit number. The argument <type> can be one of the following: w DECIMAL. Treat the string as a decimal number and cast to a signed 32-bit number. w HEX. Treat the string as a hexadecimal number and cast to a signed 32-bit number. w DECIMAL_PREFIX. Consider the part of the string up to the first occurrence of a character that is not a valid decimal character and cast to a signed 32-bit number. w HEX_PREFIX. Consider the part of the string up to the first occurrence of a character that is not a valid hexadecimal character and cast to a signed 32-bit number. For example, the following policy extracts a numeric portion of a query string, adds 4 to the number, and inserts an HTTP header named Company with the resulting decimal value. add rewrite action myadd_action insert_http_header Company "http.req.url.query.typecast _num_t(decimal).add(4)" add rewrite policy myadd_policy true myadd_action bind rewrite global myadd_policy 300 END -type RES_DEFAULT
290
Function
Description For example, this policy would extract 4444 from the following URL stub: /test/file.html?4444 The action that is associated with the policy would insert the following HTTP response header: Company: 4448\r\n
<prefix>.TYPEC AST_NUM_AT <prefix>.TYPEC AST_DOUBLE_AT <prefix>.TYPEC AST_UNSIGNED_L ONG_AT <prefix>.TYPEC AST_NUM_T(<typ e>,<default>)
Casts a number of any data type to a number of data type integer. Casts a number of any data type to a number of data type double. Casts a number of any data type to a number of data type unsigned long.
Casts string data to a signed 32-bit number. If the typecasting operation raises an undefined ( UNDEF) condition, the function returns the value specified for default. The type argument takes the values specified for TYPECAST_NUM_T(<type>). Casts string data to data of type unsigned long. The argument can be one of the following: w DECIMAL. Treat the string as a decimal number and cast to unsigned long. w HEX. Treat the string as a hexadecimal number and cast to unsigned long. w DECIMAL_PREFIX. Consider the part of the string up to the first occurrence of a character that is not a valid decimal character and cast to unsigned long.
291
Chapter 11
Typecasting Data
Function
Description w HEX_PREFIX. Consider the part of the string up to the first occurrence of a character that is not a valid hexadecimal character and cast to unsigned long.
Casts string data to data of type unsigned long. If the typecasting operation raises an undefined (UNDEF) condition, the function returns the value specified for default. The type argument takes the values specified for TYPECAST_UNSIGNED_LONG_T(<ty pe>).
292
Chapter 12
Regular Expressions
Topics:
Basic Characteristics of Regular Expressions Operations for Regular Expressions When you want to perform string matching operations that are more complex than the operations that you perform with the CONTAINS(<string>) or EQ(<string>) operators, you use regular expressions. The policy infrastructure on the Citrix NetScaler appliance includes operators to which you can pass regular expressions as arguments for text matching. The names of the operators that work with regular expressions include the string REGEX. The regular expressions that you pass as arguments must conform to the regular expression syntax that is described in http://www.pcre.org/ pcre.txt. You can learn more about regular expressions at http://www.regular-expressions.info/quickstart.html and at http://www.silverstones.com/thebat/Regex.html. The target text for an operator that works with regular expressions can be either text or the value of an HTTP header. Following is the format of a default syntax expression that uses a regular expression operator to operate on text: <text>.<regex_operator>(re<delimiter><regex_pat tern><delimiter>) The string <text> represents the default syntax expression prefix that identifies a text string in a packet (for example, HTTP.REQ.URL). The string <regex_operator> represents the regular expression operator. The regular expression always begins with the string re. A pair of matching delimiters, represented by <delimiter>, enclose the string <regex_pattern>, which represents the regular expression. The following example expression checks whether the URL in an HTTP packet contains the string *.jpeg (where * is a wildcard) and returns a Boolean TRUE or FALSE to indicate the result. The regular expression is enclosed within a pair of slash marks (/), which act as delimiters. http.req.url.regex_match(re/*.jpeg/) Regular expression operators can be combined to define or refine the scope of a search. For example, <text>.AFTER_REGEX(re/ regex_pattern1/).BEFORE_REGEX(re/ regex_pattern2/) specifies that the target for string matching is the text between the patterns regex_pattern1 and regex_pattern2. You can use a text operator on the scope that 293
Chapter 12
Regular Expressions is defined by the regular expression operators. For example, you can use the CONTAINS(<string>) operator to check whether the defined scope contains the string abc: <text>.AFTER_REGEX(re/ regex_pattern1/).BEFORE_REGEX(re/ regex_pattern2/).CONTAINS(abc) Note: The process of evaluating a regular expression inherently takes more time than that for an operator such as CONTAINS(<string>) or EQ(<string>), which work with simple string arguments. You should use regular expressions only if your requirement is beyond the scope of other operators.
294
295
Chapter 12
Regular Expressions
Description The following expression selects the string "text" from "text/plain". http.res.header("contenttype").before_regex(re#/#)
<text>.AFTER_REGEX(<regular expression>)
Selects the text that follows the string that matches the <regular expression> argument. If the regular expression does not match any text in the target, the expression returns a text object of length 0. The following expression extracts "Example" from "myExample": http.req.header("etag").after_ regex(re/my/)
<text>.REGEX_SELECT(<regular expression>)
Selects a string that matches the <regular expression> argument. If the regular expression does not match the target, a text object of length 0 is returned. The following example extracts the string "NS-CACHE-9.0: 90" from a Via header: http.req.header("via").regex_s elect(re!NS-CACHE-\d\.\d:\s* \d{1,3}!)
<text>.REGEX_MATCH(<regular expression>)
Returns TRUE if the target matches a <regular expression> argument of up to 1499 characters. The regular expression must be of the following format: re<delimiter>regular expression< delimiter> Both delimiters must be the same. Additionally, the regular expression must conform to the Perl-compatible (PCRE) regular expression library syntax. For more information, go to http:// www.pcre.org/pcre.txt. In particular,
296
Description see the pcrepattern man page. However, note the following: w Back-references are not allowed. w Recursive regular expressions are not recommended. w The dot metacharacter also matches the newline character. w The Unicode character set is not supported. w SET_TEXT_MODE(IGNORECASE) overrides the (?i) internal option specified in the regular expression. The following are examples: http.req.hostname.regex_match( re/[[:alpha:]]+(abc){2,3}/) http.req.url.set_text_mode(url encoded).regex_match(re#(a*b +c*)#) The following example matches ab and aB: http.req.url.regex_match(re/ a(?i)b/) The following example matches ab, aB, Ab and AB: http.req.url.set_text_mode(ign orecase).regex_match(re/ab/) The following example performs a caseinsensitive, multiline match in which the dot meta-character also matches a newline character: http.req.body.regex_match(re/ (?ixm) (^ab (.*) cd$) /)
297
Chapter 12
Regular Expressions
298
Chapter 13
HTTP Callouts
Topics:
How an HTTP Callout Works Notes on the Format of HTTP Requests and Responses Configuring an HTTP Callout Verifying the Configuration Invoking an HTTP Callout Avoiding HTTP Callout Recursion Deployment Scenarios for HTTP Callouts For certain types of requests, or when certain criteria are met during policy evaluation, you might want to stall policy evaluation briefly, retrieve information from a server, and then perform a specific action that depends on the information that is retrieved. At other times, when you receive certain types of requests, you might want to update a database or the content hosted on a Web server. HTTP callouts enable you to perform all these tasks. An HTTP callout is an HTTP request that the NetScaler appliance generates and sends to an external application when certain criteria are met during policy evaluation. The information that is retrieved from the server can be analyzed by default syntax policy expressions, and an appropriate action can be performed. You can configure HTTP callouts for HTTP content switching, TCP content switching, rewrite, responder, and for the token-based method of load balancing. Before you configure an HTTP callout, you must set up an application on the server to which the callout will be sent. The application, which is called the HTTP callout agent , must be configured to respond to the HTTP callout request with the required information. The HTTP callout agent can also be a Web server that serves the data for which the NetScaler appliance sends the callout. You must make sure that the format of the response to an HTTP callout does not change from one invocation to another. After you set up the HTTP callout agent, you configure the HTTP callout on the NetScaler appliance. Finally, to invoke the callout, you include the callout in a default syntax policy in the appropriate NetScaler feature and then bind the policy to the bind point at which you want the policy to be evaluated. After you have configured the HTTP callout, you must verify the configuration to make sure that the callout is working correctly.
299
Chapter 13
HTTP Callouts
300
301
Chapter 13
HTTP Callouts
Citrix NetScaler Policy Configuration and Reference Guide command-line instructions that follow include a set command for configuring an attribute-based callout and a set command for configuring an expression-based callout. In the NetScaler configuration utility, all of these configuration tasks are performed in a single dialog box. Note: Before you put an HTTP callout into a policy, you can modify all configured parameters except the return type. Once an HTTP callout is in a policy, you cannot completely modify an expression that is configured in the callout. For example, you cannot change HTTP.REQ.HEADER("myval") to CLIENT.IP.SRC. However, you can modify the operators and arguments that are passed to the expression. For example, you can change HTTP.REQ.HEADER("myVal1") to HTTP.REQ.HEADER("myVal2"), or HTTP.REQ.HEADER("myVal") to HTTP.REQ.HEADER("myVal").AFTER_STR(<string>). If the set command fails, create a new HTTP callout. HTTP callout configuration involves configuring default syntax expressions. For more information about configuring default syntax expressions, see Configuring Default Syntax Expressions: Getting Started on page 75.
303
Chapter 13
HTTP Callouts
304
Citrix NetScaler Policy Configuration and Reference Guide w set policy httpCallout <name> [-vServer <string>] [-returnType <returnType>] [httpMethod ( GET | POST )] [-fullReqExpr <string>] [-resultExpr <string>] w show policy httpCallout <name> Example > add policy httpCallout mycallout1 Done set policy httpCallout mycallout1 -vserver lbv1 returnType num -httpMethod GET -fullReqExpr q{"GET " + http.req.url + "HTTP/" + http.req.version.major + "." + http.req.version.minor.sub(1)+ "r\nHost: 10.101.10.10\r\nAccept: */*\r\n\r\n"} Done show policy httpCallout mycallout1 Name: mycallout1 Vserver: lbv1 (UP) Return type: NUM Full REQ expr: "GET " + http.req.url + "HTTP/" + http.req.version.major + "." + http.req.version.minor.sub(1)+ "r\nHost: 10.101.10.10\r\nAccept: */*\r\n\r\n" Result expr: NONE Hits: 0 Undef Hits: 0 Last undef reason: Config incomplete Done >
To set an HTTP callout parameter to the default value by using the NetScaler command line
At the NetScaler command prompt, type the following commands to view the configuration of an HTTP callout, set a parameter to the default value, and verify the configuration: w show policy httpCallout <name> w unset policy httpCallout <name> [-IPAddress] [-port] [-vServer] [-httpMethod] [hostExpr] [-urlStemExpr] [-headers] [-parameters] [-fullReqExpr] [-resultExpr]<name> w show policy httpCallout Example > show policy httpCallout myCallout Name: myCallout Server: 10.102.3.96:443 (DOWN) Return type: TEXT Method: POST Host expr: "10.102.3.95" URL stem: "/cgi-bin/ check_clnt_from_database.pl" 305
Chapter 13
HTTP Callouts Headers: Request("Callout Request") Parameters: param1("user1") param2("user2") Result expr: HTTP.RES.BODY(100) Hits: 0 Undef Hits: 0 Last undef reason: Server is DOWN Done > unset policy httpCallout myCallout -httpMethod Done > show policy httpCallout myCallout Name: myCallout Server: 10.102.3.96:443 (DOWN) Return type: TEXT Method: GET Host expr: "10.102.3.95" URL stem: "/cgi-bin/ check_clnt_from_database.pl" Headers: Request("Callout Request") Parameters: param1("user1") param2("user2") Result expr: HTTP.RES.BODY(100) Hits: 0 Undef Hits: 0 Last undef reason: Server is DOWN Done >
306
Citrix NetScaler Policy Configuration and Reference Guide vServer The name of the load balancing, content switching, or cache redirection virtual server to which the HTTP callout is sent. The service type of the virtual server must be HTTP. This option is mutually exclusive with -IPAddress and -port. The maximum length is 127 characters. returnType Type of data that the target application returns in the response to the callout. Possible values: BOOL, NUM, TEXT. httpMethod Method used in the HTTP request that this callout sends. Mutually exclusive with fullReqExpr. Possible values: GET, POST. hostExpr Text expression to configure the Host header. The expression can contain a literal value (10.101.10.11) or a derived value (for example, HTTP.REQ.HEADER). The literal value can be an IP address or a fully qualified domain name. Mutually exclusive with -fullReqExpr. Maximum length: 255. urlStemExpr A string expression for generating the URL stem. The expression can contain a literal string (for example, /mysite/index.html) or an expression that derives the value (for example, HTTP.REQ.URL). Mutually exclusive with -fullReqExpr. Maximum length: 8191. headers Text expression to insert HTTP headers and their values in the HTTP callout request. You must specify a value for every header. You specify the header name as a string and the header value as an expression. You can configure a maximum of eight headers for an HTTP callout. Mutually exclusive with -fullReqExpr. parameters Expression to insert query parameters in the HTTP request that the callout sends. You must specify a value for every parameter that you configure. If the callout request uses the GET method, these parameters are inserted in the URL. If the callout request uses the POST method, these parameters are inserted in the POST body. You configure the query parameter name as a string, and the value as an expression. The parameter values are URL encoded. Mutually exclusive with -fullReqExpr.
307
Chapter 13
HTTP Callouts fullReqExpr Exact HTTP request that the NetScaler appliance is to send, as an expression. If you specify this parameter, you must omit the httpMethod, hostExpr, urlStemExpr, headers, and parameters arguments. The request expression is constrained by the feature for which the callout is used. For example, an HTTP.RES expression cannot be used in a request-time policy bank or in a TCP content switching policy bank. The NetScaler appliance does not check the validity of this request. You must manually validate the request. The maximum length of the input expression is 8191 characters. The maximum length of a string literal that can be used inside the expression is 255 characters. A string literal that contains more than 255 characters can be split into smaller strings of 255 characters each. The smaller strings can then be concatenated with the + operator to obtain the original string literal. For example, if a string is 500 characters long, you can split the string into smaller strings and concatenate them as shown: '"<string of length 255 characters>" + "<string of length 245 characters>"' resultExpr Expression that extracts objects from the response sent by the HTTP callout agent. The expression must be a response-based expression, that is, it must begin with HTTP.RES. The operations in this expression must match the return type. For example, if you configure a return type of TEXT, the result expression must be a text-based expression. If the return type is NUM, the result expression (resultExpr) must return a numeric value, as in the following example: HTTP.RES.BODY(10000).LENGTH Maximum length: 8191.
Citrix NetScaler Policy Configuration and Reference Guide Name*name (cannot be changed for an existing HTTP callout). Virtual ServervServer IP AddressIPAddress IPv6: If you want to enter an IPv6 address, select this check box. Portport w If you want to configure an attribute-based HTTP callout, click Attribute-based, click Configure Request Attributes, and then, in the Configure HTTP Callout Request Attributes dialog box, specify values for the following parameters, which correspond to the parameters described in the "Parameters for configuring an HTTP callout" as shown: MethodhttpMethod Host ExpressionhostExpr URL Stem ExpressionurlStemExpr Headersheaders (After you enter a header name and its value, click Add, and then enter the next header-value pair.) Parametersparameters (After you enter a parameter name and its value, click Add, and then enter the next parameter-value pair.) w If you want to configure an expression-based HTTP callout, click Expression-based, and then, in the space provided, configure the expression. This expression corresponds to the -fullReqExpr parameter that is described in "Parameters for configuring an HTTP callout." w In the Server Response area, specify values for the following parameters, which correspond to the parameters described in the "Parameters for configuring an HTTP callout" as shown: Return TypereturnType Expression to extract data from the responseresultExpr w Click Create or OK. w Verify that the HTTP callout is correctly configured by selecting the callout and viewing the Details section at the bottom of the details pane.
309
Chapter 13
HTTP Callouts Table 13-1. Icons That Indicate the States of Entities Bound to an HTTP Callout Icon Indicates that The state of the server that hosts the HTTP callout agent, or the load balancing, content switching, or cache redirection virtual server to which the HTTP callout is sent is UP. The state of the server that hosts the HTTP callout agent, or the load balancing, content switching, or cache redirection virtual server to which the HTTP callout is sent is OUT OF SERVICE. The state of the server that hosts the HTTP callout agent, or the load balancing, content switching, or cache redirection virtual server to which the HTTP callout is sent is DOWN. For an HTTP callout to function correctly, the icon must be green at all times. If the icon is not green, check the state of the callout server or virtual server to which the HTTP callout is sent. If the HTTP callout is not working as expected even though the icon is green, check the parameters configured for the callout. You can also verify the configuration by sending test requests that match the policy from which the HTTP callout is invoked, checking the hits counter for the policy and the HTTP callout, and verifying the responses that the NetScaler appliance sends to the client. Note: An HTTP callout can sometimes invoke itself recursively a second time. If this happens, the hits counter is incremented by two counts for each callout that is generated by the appliance. For the hits counter to display the correct value, you must configure the HTTP callout in such a way that it does not invoke itself a second time. For more information about how you can avoid HTTP callout recursion, see Avoiding HTTP Callout Recursion on page 312.
Citrix NetScaler Policy Configuration and Reference Guide response. If the part of the response that you want to analyze is text, you can use a text operator to analyze the response. For example, you can use the CONTAINS(<string>) operator to check whether the specified portion of the response contains a particular string, as in the following example: SYS.HTTP_CALLOUT(mycallout).contains("Good IP address") If you use the preceding expression in a responder policy, you can configure an appropriate responder action. Similarly, if the part of the response that you want to evaluate is a number, you can use a numeric operator such as GT(int). If the response contains a Boolean value, you can use a Boolean operator. Note: An HTTP callout can invoke itself recursively. HTTP callout recursion can be avoided by combining the HTTP callout expression with a default syntax expression that prevents recursion. For information about how you can avoid HTTP callout recursion, see Avoiding HTTP Callout Recursion on page 312. You can also cascade HTTP callouts by configuring policies that each invoke a callout after evaluating previously generated callouts. In this scenario, after one policy invokes a callout, when the NetScaler appliance is parsing the callout before sending the callout to the callout server, a second set of policies can evaluate the callout and invoke additional callouts, which can in turn be evaluated by a third set of policies, and so on. Such an implementation is described in the following example. First, you could configure an HTTP callout called myCallout1, and then configure a responder policy, Pol1, to invoke myCallout1. Then, you could configure a second HTTP callout, myCallout2, and a responder policy, Pol2. You configure Pol2 to evaluate myCallout1 and invoke myCallout2. You bind both responder policies globally. To avoid HTTP callout recursion, myCallout1 is configured with a unique custom HTTP header called "Request1." Pol1 is configured to avoid HTTP callout recursion by using the default syntax expression, HTTP.REQ.HEADER(\"Request1\").EQ(\"Callout Request\").NOT. Pol2 uses the same default syntax expression, but excludes the .NOT operator so that the policy evaluates myCallout1 when the NetScaler appliance is parsing it. Note that myCallout2 identifies its own unique header called "Request2," and Pol2 includes a default syntax expression to prevent myCallout2 from invoking itself recursively. Example > add policy httpCallout myCallout1 Done > set policy httpCallout myCallout1 -IPAddress 10.102.3.95 -port 80 -returnType TEXT -hostExpr "\"10.102.3.95\"" -urlStemExpr "\"/cgi-bin/ check_clnt_from_database.pl\"" -headers Request1 ("Callout Request") -parameters cip(CLIENT.IP.SRC) resultExpr "HTTP.RES.BODY(100)" 311
Chapter 13
HTTP Callouts
Done > add responder policy Pol1 "HTTP.REQ.HEADER(\"Request1\").EQ(\"Callout Request \").NOT && SYS.HTTP_CALLOUT(myCallout1).CONTAINS(\"IP Matched \")" RESET Done > bind responder global Pol1 100 END -type OVERRIDE Done > add policy httpCallout myCallout2 Done > set policy httpCallout myCallout2 -IPAddress 10.102.3.96 -port 80 -returnType TEXT -hostExpr "\"10.102.3.96\"" -urlStemExpr "\"/cgi-bin/ check_clnt_location_from_database.pl\"" -headers Request2 ("Callout Request") -parameters cip(CLIENT.IP.SRC) resultExpr "HTTP.RES.BODY(200)" Done > add responder policy Pol2 "HTTP.REQ.HEADER(\"Request2\").EQ(\"Callout Request \").NOT && HTTP.REQ.HEADER(\"Request1\").EQ(\"Callout Request \") && SYS.HTTP_CALLOUT(myCallout2).CONTAINS (\"APAC\")" RESET Done > bind responder global Pol2 110 END -type OVERRIDE Done
Citrix NetScaler Policy Configuration and Reference Guide invocation results in the policy and HTTP callout hit counters being incremented by two counts each instead of one count each. To prevent a callout from invoking itself, you must identify at least one unique characteristic of the HTTP callout request, and then exclude all requests with this characteristic from being processed by the policy rule that invokes the callout. You can do so by including another default syntax expression in the policy rule. The expression must precede the SYS.HTTP_CALLOUT(<name>) expression so that it is evaluated before the callout expression is evaluated. For example: <Expression that prevents callout recursion> && SYS.HTTP_CALLOUT(<name>) When you configure a policy rule in this way, when the NetScaler appliance generates the request and parses it, the compound rule evaluates to FALSE, the callout is not generated a second time, and the hit counters are incremented correctly. One way by which you can assign a unique characteristic to an HTTP callout request is to include a unique custom HTTP header when you configure the callout. Following is an example of an HTTP callout called "myCallout." The callout generates an HTTP request that checks whether a clients IP address is present in a database of blacklisted IP addresses. The callout includes a custom header called "Request," which is set to the value "Callout Request." A globally bound responder policy, "Pol1," invokes the HTTP callout but excludes all requests whose Request header is set to this value, thus preventing a second invocation of myCallout. The expression that prevents a second invocation is HTTP.REQ.HEADER(\"Request\").EQ(\"Callout Request \").NOT. Example > add policy httpCallout myCallout Done > set policy httpCallout myCallout -IPAddress 10.102.3.95 -port 80 -returnType TEXT -hostExpr "\"10.102.3.95\"" -urlStemExpr "\"/cgi-bin/ check_clnt_from_database.pl\"" -headers Request("Callout Request") -parameters cip(CLIENT.IP.SRC) -resultExpr "HTTP.RES.BODY(100)" Done > add responder policy Pol1 "HTTP.REQ.HEADER(\"Request\").EQ(\"Callout Request \").NOT && SYS.HTTP_CALLOUT(myCallout).CONTAINS(\"IP Matched \")" RESET Done > bind responder global Pol1 100 END -type OVERRIDE Done Note: You can also configure an expression to check whether the URL of the request includes the URL stem expression that is configured for the HTTP callout. If you want to implement this scenario, make sure that the HTTP callout agent is dedicated to respond only to HTTP callouts and not to other client requests
313
Chapter 13
HTTP Callouts
directed through the NetScaler appliance. If the HTTP callout agent is an application or Web server that serves other client requests, such an expression will prevent the NetScaler appliance from processing those client requests. Instead, use a unique custom header as described earlier.
Enabling Responder
You must enable responder before you can use it.
314
Citrix NetScaler Policy Configuration and Reference Guide 2. In the navigation pane, right-click Responder, and then click Enable Responder feature.
Request to send to the server Method Host Expression URL Stem Expression Headers Name Value-expression Parameters Name Value-expression Server Response Return Type Expression to extract data from the response TEXT HTTP.RES.BODY(100) Cip CLIENT.IP.SRC Request Callout Request GET 10.102.3.95 "/cgi-bin/check_clnt_from_database.pl"
Chapter 13
HTTP Callouts
To create a responder policy and bind it globally by using the configuration utility
1. In the navigation pane, click Responder. 2. In the details pane, under Policy Manager, click Policy Manager. 3. In the Responder Policy Manager dialog box, click Override Global. 4. Click Insert Policy, and then, under Policy Name, click New Policy. 5. In the Create Responder Policy dialog box, do the following: a. In Name, type Policy-Responder-1. b. In Action, select RESET. c. In Undefined-Result Action, select Global undefined-result action. d. In Expression, type the following default syntax expression: "HTTP.REQ.HEADER(\"Request\").EQ(\"Callout Request\").NOT && SYS.HTTP_CALLOUT(HTTP-Callout-1).CONTAINS(\"IP Matched \")" e. Click Create, and then click Close. 6. Click Apply Changes, and then click Close.
Citrix NetScaler Policy Configuration and Reference Guide my $sth = $dbh->prepare(qq{ select * from bad_clnt }); $sth->execute(); while (my ($ip_in_database) = $sth->fetchrow_array()) { chomp($ip_in_database); # Check for IP match if ($ip_in_database eq $ip_to_check) { print "\n IP Matched\n"; $sth>finish(); exit; } } print "\n IP Failed\n"; $sth->finish(); exit;
Enabling Rewrite
Rewrite must be enabled before it is used on the NetScaler appliance. The following procedure describes the steps to enable the rewrite feature.
Chapter 13
HTTP Callouts Table 13-3. Parameters and Values for HTTP-Callout-2 Parameter Name Value HTTP-Callout-2
Request to send to the server Method Host Expression URL Stem Expression Headers Name Value-expression Server Response Return Type Expression to extract data from the response TEXT HTTP.RES.BODY(100) Name Callout GET 10.102.56.51:80 "HTTP.RES.BODY(500).AFTER_STR(\"src= \").BEFORE_STR(\"/>\")"
318
To configure a rewrite policy and bind it globally by using the configuration utility
1. In the navigation pane, expand Rewrite. 2. In the details pane, under Policy Manager, click Rewrite Policy Manager. 3. In the Rewrite Policy Manager dialog box, click Override Global. 4. Click Insert Policy, and then, in the Policy Name column, click New Policy. 5. In the Create Rewrite Policy dialog box, do the following: 319
Chapter 13
HTTP Callouts a. In Name, type Policy-Rewrite-1. b. In Action, select Action-Rewrite-1. c. In Undefined-Result Action, select Global undefined-result action. d. In Expression, type the following default syntax expression: "HTTP.REQ.HEADER(\"Name\").CONTAINS(\"Callout\").NOT" e. Click Create, and then click Close. 6. Click Apply Changes, and then click Close.
Enabling Responder
The responder feature must be enabled before it is used on the NetScaler appliance.
320
Citrix NetScaler Policy Configuration and Reference Guide Table 13-6. Parameters and Values for HTTP-Callout-3 Parameter Name Server to receive callout request IP Address Port Request to send to the server Method Host Expression URL Stem Expression Headers Name Value-expression Parameters Name Value-expression Name Value-expression Server Response Return Type Expression to extract data from the response TEXT HTTP.RES.BODY(100) Username HTTP.REQ.HEADER("Username").VALUE(0) Password HTTP.REQ.HEADER("Password").VALUE(0) Request Callout Request GET 10.102.3.95 /cgi-bin/authenticate.pl 10.103.9.95 80 Value HTTP-Callout-3
321
Chapter 13
HTTP Callouts Table 13-7. Parameters and Values for Policy-Responder-3 Parameter Name Action Undefined-Result-Action Expression Value Policy-Responder-3 RESET -Global undefined-result action"HTTP.REQ.HEADER(\"Request \").EQ(\"Callout Request\").NOT && SYS.HTTP_CALLOUT(HTTPCallout-3).CONTAINS(\"Authentication Failed\")"
To create a responder policy and bind it globally by using the configuration utility
1. In the navigation pane, expand Responder. 2. In the details pane, under Policy Manager, click Responder Policy Manager. 3. In the Responder Policy Manger dialog box, click Override Global. 4. Click Insert Policy, and then, in the Policy Name column, click New Policy. 5. In the Create Responder Policy dialog box, do the following: a. In Name, type Policy-Responder-3. b. In Action, select RESET. c. In Undefined-Result Action , select Global undefined-result action. d. In the Expression text box, type: "HTTP.REQ.HEADER(\"Request\").EQ(\"Callout Request\").NOT && SYS.HTTP_CALLOUT(HTTPCallout-3).CONTAINS(\"Authentication Failed\")" e. Click Create, and then click Close. 6. Click Apply Changes, and then click Close.
Enabling Responder
The responder feature must be enabled before it can be used on the NetScaler appliance.
323
Chapter 13
HTTP Callouts
Server Response Return Type Expression to extract data from the response BOOL HTTP.RES.BODY(100) .CONTAINS(\"Matched\")
324
Citrix NetScaler Policy Configuration and Reference Guide Table 13-9. Parameters and Values for Action-Responder-4 Parameter Name Type Target Value Action-Responder-4 Respond with "\"HTTP/1.1 200 OK\r\nServer: MicrosoftIIS/6.0\r\nX-Powered-By: ASP.NET\r \nContent-Length: 0\r\nMS-WebStorage: 6.5.6944\r\nCache-Control: no-cache\r\n \r\n\""
325
Chapter 13
HTTP Callouts
326
Chapter 14
Pattern Sets
Topics:
How String Matching with a Pattern Set Works Configuring a Pattern Set Using a Pattern Set Pattern Set Operators A pattern set is an array of indexed patterns that you configure on the Citrix NetScaler appliance. Pattern sets are used for string matching during default syntax policy evaluation. The NetScaler appliance provides you with a set of default syntax expression operators that you can use to compare a string in a packet with the patterns that are indexed and stored in a pattern set. You can configure the appliance to compare the string that is identified in a packet with one or more patterns in the pattern set by using a simple default syntax expression combined with an operator. Additionally, after you create a pattern set, you can use the pattern set in multiple default syntax policies. Therefore, pattern sets eliminate the need for you to configure compound default syntax expressions that perform string matching with multiple OR operations (one expression for each comparison). This also reduces the consumption of appliance resources in terms of memory and the number of expressions that the appliance has to evaluate. First, you create a pattern set and bind patterns to it. Then, when you configure a policy for comparing a string in a packet with the pattern set, you use an appropriate operator and pass the name of the pattern set as an argument.
327
Chapter 14
Pattern Sets
Example 1. The following default syntax expression identifies the URL suffix in an HTTP packet. The operator EQUALS_ANY compares the suffix to the image file extensions defined in imagetypes and returns a Boolean value to indicate the result of the comparison. HTTP.REQ.URL.SUFFIX.EQUALS_ANY("imagetypes") If the URL in the incoming HTTP packet that the appliance is evaluating is http:// www.example.com/homepageicon.jpeg, the operator returns a Boolean TRUE. Example 2. The following default syntax expression identifies the URL suffix in an HTTP packet. The operator EQUALS_INDEX compares the suffix to the image file extensions defined in imagetypes, and returns the index of the string that matches the URL suffix, if any. HTTP.REQ.URL.SUFFIX.EQUALS_INDEX("imagetypes") If the URL in an incoming HTTP packet is http://www.example.com/mylogo.gif, the operator returns 4, which is the index of the pattern gif. You can further evaluate the index value by using operators that work with numbers. This is particularly useful 328
Citrix NetScaler Policy Configuration and Reference Guide when you have a large pattern set but want to perform a policy action only if the index has a particular value or lies within a specified range. Following is an example of a compound expression that uses the GE(int) and LE(int) operators to determine whether a URL suffix is gif, tiff, or svg. If the compound expression evaluates to TRUE, an action is performed. HTTP.REQ.URL.SUFFIX.EQUALS_INDEX("imagetypes").GE(4) && HTTP.REQ.URL.SUFFIX.EQUALS_INDEX("imagetypes").LE(6) An expression that returns the index of a matched pattern can be used to define traffic subsets for a Web application. If you want to implement one set of NetScaler policies for BMP, JPEG, and PNG files, and a different set of policies for GIF, TIFF, and SVG files, you can use the pattern set imagetypes and define the following two content switching policies for a content switching virtual server: HTTP.REQ.URL.SUFFIX.EQUALS_INDEX("imagetypes").LE(3) HTTP.REQ.URL.SUFFIX.EQUALS_INDEX("imagetypes").GE(4) For a complete list of the operators that are available for pattern sets and their descriptions, see Pattern Set Operators on page 332.
329
Chapter 14
Pattern Sets
To bind a pattern to the pattern set by using the NetScaler command line
At the NetScaler command prompt, type the following commands to bind a pattern to the pattern set and verify the configuration w bind policy patset <name> <string> [-index <positive_integer>] w show policy patset <name> Example bind policy patset samplepatset product1 -index 1 Done show policy patset samplepatset Index is user-configured for the patset 1) Bound Pattern: product1 Index: 1 Done >
To unbind a pattern from a pattern set by using the NetScaler command line
At the NetScaler command prompt, type the following commands to unbind a pattern from the pattern set and verify the configuration: w unbind policy patset <name> <string> w show policy patset <name> Example > unbind policy patset samplepatset product1 Done > show policy patset samplepatset 330
>
index The index of the pattern that is bound to the pattern set. This is an optional argument. Minimum value: 1. Maximum value: 4294967290.
Chapter 14
Pattern Sets 3. If creating a pattern set, in the Name text box, type a name for the pattern set (maximum length, 127 characters). 4. Under Specify Pattern, type the first pattern and, optionally, specify values for the following parameters: Treat back slash as escape characterSelect this check box to specify that any backslash characters that you might include in the pattern are to be treated as escape characters. IndexA user assigned index value, from 1 through 4294967290. 5. Verify that you have entered the correct characters, and then click Add. 6. Repeat steps 4 and 5 to add additional patterns, and then click Create or OK.
332
Citrix NetScaler Policy Configuration and Reference Guide Table 14-2. Operators for Pattern Set Operator <text>.CONTAINS_ANY(<pattern_s et_name>) Description Evaluates whether the target text contains any of the patterns that are bound to <pattern_set_name> and returns a Boolean TRUE if one or more matching patterns are found. Selects the first string that matches any pattern in the given pattern set. Evaluates whether the target text exactly matches any of the patterns that are bound to <pattern_set_name> and returns a Boolean TRUE or FALSE to indicate the result of the evaluation. Evaluates whether the target text ends with any of the patterns that are bound to <pattern_set_name> and returns a Boolean TRUE or FALSE to indicate the result of the evaluation. Evaluates whether the target text starts with any of the patterns that are bound to <pattern_set_name> and returns a Boolean TRUE or FALSE to indicate the result of the evaluation. Evaluates whether the target text starts with any of the patterns that are bound to <pattern_set_name> and, if a match is found, returns the numerical index of the matching pattern. Evaluates whether the target text ends with any of the patterns that are bound to <pattern_set_name> and, if a match is found, returns the numerical index of the matching pattern. Evaluates whether the target text contains any of the patterns that are bound to <pattern_set_name> and, if a match is found, returns the numerical index of the matching pattern. Evaluates whether the target text exactly matches any of the patterns that
<text>.ENDSWITH_ANY(<pattern_s et_name>)
<text>.STARTSWITH_ANY(<pattern _set_name>)
<text>.STARTSWITH_INDEX(<patte rn_set_name>)
<text>.ENDSWITH_INDEX(<pattern _set_name>)
<text>.CONTAINS_INDEX(<pattern _set_name>)
<text>.EQUALS_INDEX(<pattern_s et_name>)
333
Chapter 14
Pattern Sets
Operator
Description are bound to <pattern_set_name> and, if an exact match is found, returns the numerical index of the pattern.
334
Chapter 15
String Maps
Topics:
How String Maps Work Configuring a String Map String Maps Use Cases You can use string maps to perform pattern matching in all NetScaler features that use the default policy syntax. A string map is a NetScaler entity that consists of key-value pairs. The keys and values are strings in either ASCII or UTF-8 format. String comparison uses two new functions, MAP_STRING(<string_map_name>) and IS_STRINGMAP_KEY(<string_map_name>). A policy configuration that uses string maps performs better than one that does string matching through policy expressions, and you need fewer policies to perform string matching with a large number of key-value pairs. String maps are also intuitive, simple to configure, and result in a smaller configuration.
335
Chapter 15
String Maps
The following table describes the two functions that have been introduced to enable string matching with keys in a string map. String matching is always performed with the keys. Additionally, the following functions perform a comparison between the keys in the string map and the complete string that is returned by the expression prefix. The examples in the descriptions refer to the preceding example. Table 15-2. String Map Functions Function <TEXT>.MAP_STRING(<string_map_ name>) Description Checks whether the value returned by the expression prefix TEXT matches any of the keys in the string map, and returns the value that corresponds to the key. If no key in the string map matches the value returned by the expression prefix, the function returns a null string. The IGNORECASE and NOIGNORECASE functions can be used for caseinsensitive and case-sensitive comparison, respectively. Example 1: HTTP.REQ.URL.MAP_STRING("url_s tring_map") checks whether the string
336
Function
Description returned by HTTP.REQ.URL is a key in the string map url_string_map. If the value of HTTP.REQ.URL is / url_1.html, the function returns http://www.redirect_url_1.com/ url_1.html. Example 2: HTTP.REQ.URL.SET_TEXT_MODE(IGN ORECASE).MAP_STRING("url_strin g_map") checks whether the string returned by HTTP.REQ.URL is a key in the string map url_string_map. The comparison does not consider case. If the string returned by HTTP.REQ.URL is /URL_1.html, the function returns http://www.redirect_url_1.com/ url_1.html. Parameters: string_map_name - The string map.
<TEXT>.IS_STRINGMAP_KEY(<strin g_map_name>)
Returns TRUE if the string returned by the expression prefix TEXT is a key in the string map. The IGNORECASE and NOIGNORECASE functions can be used for case-insensitive and case-sensitive string matching, respectively. Example 1: HTTP.REQ.URL.IS_STRINGMAP_KEY( "url_string_map") returns TRUE if the value of HTTP.REQ.URL is one of the keys in url_string_map. Example 2: HTTP.REQ.URL.SET_TEXT_MODE(IGN ORECASE). IS_STRINGMAP_KEY("url_string_m ap") returns TRUE if the value of HTTP.REQ.URL is one of the keys in url_string_map. In this case, key lookup does not consider case. Therefore, the function returns TRUE even if the value of HTTP.REQ.URL is /URL_3.html.
337
Chapter 15
String Maps
Function
To bind a key-value pair to the string map by using the NetScaler command line
At the NetScaler command prompt, type the following commands to bind a key-value pair to a string map and verify the configuration: w bind policy stringmap <name> <key> <value> w show policy stringmap <name> Example > bind policy stringmap url_string_map1 "/url_1.html" "http:// www.redirect_url_1.com/url_1.html" Done > show policy stringmap url_string_map1 String map: url_string_map1 1) Key: /url_1.html Value: www.redirect_url_1.com/url_1.html Done > 338 http://
Citrix NetScaler Policy Configuration and Reference Guide After you create a string map, you can modify only the comment parameter from the command line. To modify a string map by using the NetScaler command line, type the set policy stringmap command followed by the name of the string map and the comment parameter with its new value.
Chapter 15
String Maps
340
Chapter 16
Rate Limiting
Topics:
Configuring a Traffic Limit Selector Configuring a Traffic Rate Limit Identifier Configuring and Binding a Traffic Rate Policy Viewing the Traffic Rate Testing a Rate-Based Policy Examples of Rate-Based Policies The rate limiting feature enables you to define the maximum load for a given network entity or virtual entity on the Citrix NetScaler appliance. The feature enables you to configure the appliance to monitor the rate of traffic associated with the entity and take preventive action, in real time, based on the traffic rate. This feature is particularly useful when the network is under attack from a hostile client that is sending the appliance a flood of requests. You can mitigate the risks that affect the availability of resources to clients, and you can improve the reliability of the network and the resources that the appliance manages. You can monitor and control the rate of traffic that is associated with virtual and user-defined entities, including virtual servers, URLs, domains, and combinations of URLs and domains. You can throttle the rate of traffic if it is too high, base information caching on the traffic rate, and redirect traffic to a given load balancing virtual server if the traffic rate exceeds a predefined limit. You can apply rate-based monitoring to HTTP, TCP, and DNS requests. To monitor the rate of traffic for a given scenario, you configure a rate limit identifier. A rate limit identifier specifies numeric thresholds such as the maximum number of requests or connections (of a particular type) that are permitted in a specified time period called a time slice. Optionally, you can configure filters, known as rate limit selectors, and associate them with rate limit identifiers when you configure the identifiers. After you configure the optional limit selector and the limit identifier, you must invoke the limit identifier from a default syntax policy. You can invoke identifiers from any feature in which the identifier may be useful, including Rewrite, Responder, DNS, and Integrated Caching. You can globally enable and disable SNMP traps for rate limit identifiers. Each trap contains cumulative data for the rate limit identifier's configured data collection interval (time slice), unless you specified multiple traps to be generated per time slice. For more information about configuring SNMP traps and managers, see the "SNMP" chapter in the Citrix NetScaler Administration Guide at http://support.citrix.com/article/ CTX132357. 341
Chapter 16
Rate Limiting
Citrix NetScaler Policy Configuration and Reference Guide client_dns_domain_and_source_ip client.udp.dns.domain client.ip.src Done > show ns limitSelector client_dns_domain_and_source_ip Name: client_dns_domain_and_source_ip Expressions: 1) client.udp.dns.domain 2) client.ip.src Done >
343
Chapter 16
Rate Limiting Name*selectorName Expressionsrule * A required parameter Note: In the Expressions box, enter a valid parameter. For example, enter http. Then, enter a period after this parameter. A drop-down menu appears. The contents of this menu provide the keywords that can follow the initial keyword that you entered. To select the next keyword in this expression prefix, double-click the selection in the drop-down menu. The Expressions text box displays both the first and second keywords for the expression prefix, for example, http.req. Continue adding expression components until the complete expression is formed. 4. Click Add. 5. Continue adding up to five non-compound expressions (selectlets). 6. Click Create or OK.
Citrix NetScaler Policy Configuration and Reference Guide Name: 100_request_limit Threshold: 100 Timeslice: 1000 Traps : 30 Max Bandwidth: 0 kbps Selector: limit_100_requests_selector Mode: REQUEST_RATE Type: BURSTY Expressions: 1) HTTP.REQ.METHOD 2) CLIENT.IP.SRC Permit 100 Requests in 1000 ms Generate 30 Traps in 1000 ms Hits: 0 Action Taken: 0 Done >
Chapter 16
Rate Limiting Default: REQUEST_RATE. limitType Whether traffic is smooth or occurs in bursts when you configure the mode to be REQUEST_RATE: w BURSTY: Most of the traffic arrives at one point in the interval (for example, the first 10 milliseconds (ms) of a one-second interval). An example of a bursty application is a Web page that may have a flurry of activity when a user accesses it, and then no activity as the user reads the page. w SMOOTH: An even distribution over the interval (for example, ten requests every ten milliseconds). If you choose SMOOTH, the NetScaler tracks requests at 10/ms intervals. For example, if you specify 4 requests per 200 ms, the NetScaler tracks at a rate of 1 request every 50 ms. Possible values: BURSTY and SMOOTH. Default: BURSTY.. selectorName The name of rate limit selector. Maximum Length: 31 maxBandwidth Maximum bandwidth permitted, in kilobits (Kbps). The default value, 0, means that bandwidth is not used in this identifier. Minimum value: 0. Maximum value: 4294967287. Default: 0. trapsInTimeSlice Number of SNMP traps to send in the time slice. A value of zero means that traps are disabled. Default: 0. Minimum: 0. Maximum: 65535. Traps are per identifier, not per identifier record. Use traps per time slice to increase the number of traps that are generated. -trapsinTimeSlice positive_integer.
Name*limitIdentifier SelectorselectorName (To create a new selector, click New next to the dropdown menu and define a selector as described in Configuring a Traffic Limit Selector on page 342.) Modemode Limit TypelimitType Thresholdthreshold Time SlicetimeSlice Max BandwidthmaxBandwidth TrapstrapsInTimeSlice * A required parameter 4. Click Create or OK.
Chapter 16
Rate Limiting
Following is a complete example of a rate-based policy rule. Note that this example assumes that you have configured the responder action, send_direct_url, that is associated with the policy. Note that the sys.check_limit parameter must be the last element of the policy expression: add responder policy responder_threshold_policy "http.req.url.contains(\"myindex.html\") && sys.check_limit(\"my_limit_identifier\")" send_direct_url For information about binding a policy globally or to a virtual server, see Binding Policies That Use the Default Syntax on page 41.
Citrix NetScaler Policy Configuration and Reference Guide 4. Enter feature-specific information about the policy. For example, you may be required to associate the policy with an action or a profile. For more information, see the feature-specific documentation. 5. Click Create, and then click Close. 6. Click Save.
Chapter 16
Rate Limiting this identifier), the Session Details dialog box appears. Otherwise, you receive a No session exists message.
Citrix NetScaler Policy Configuration and Reference Guide 1) 10.217.253.0 Active Transactions: 0
>
Done
7. Repeat the query and check the limit identifier statistics again to verify that the statistics are being updated correctly.
351
Chapter 16
Rate Limiting
Purpose Drop a connection on the basis of cookies received in requests from www.yourcompany.com if these requests exceed the rate limit
Example add ns limitSelector reqCookieLimitSelector "http.req.cookie .value(\"mycookie\")" "client.ip.src.subnet(24)" add ns limitIdentifier myLimitIdentifier Threshold 2 -timeSlice 3000 -selectorName reqCookieLimitSelector add responder action sendRedirectUrl redirect '\"http://www.mycompany.com\" + http.req.url' -bypassSafetyCheck YES add responder policy rateLimitCookiePolicy "http.req.url.contains(\"www.yourcompany. com\") && sys.check_limit(\"myLimitIdentifier \")" sendRedirectUrl
Drop a DNS packet if the requests from a particular client IP address and DNS domain exceed the rate limit
add ns limitSelector dropDNSRateSelector client.udp.dns.domain client.ip.src add ns limitIdentifier dropDNSRateIdentifier -timeslice 20000 mode request_rate -selectorName dropDNSRateSelector maxBandwidth 1 -trapsintimeslice 20 add dns policy dnsDropOnClientRatePolicy "sys.check_limit (\"dropDNSRateIdentifier\")" -drop yes
Limit the number of HTTP requests that arrive from the same subnet (with a subnet mask of 32) and that have the same destination IP address.
add ns limitSelector ipv6_sel "CLIENT.IPv6.src.subnet(32)" CLIENT.IPv6.dst Q.URL add ns limitIdentifier ipv6_id -imeSlice 20000 -selectorName ipv6_sel add lb vserver ipv6_vip HTTP 3ffe::209 80 -persistenceType NONE -cltTimeout 180 add responder action redirect_page redirect "\"http://redirectpage.com/\"" add responder policy ipv6_resp_pol "SYS.CHECK_LIMIT(\"ipv6_id\")" redirect_page bind responder global ipv6_resp_pol 5 END -type DEFAULT
352
Chapter 16
Rate Limiting Configured Method: STATICPROXIMITY BackupMethod: ROUNDROBIN No. of Bound Services : 3 (Total) 3 (Active) Persistence: NONE Persistence ID: 100 Disable Primary Vserver on Down: DISABLED Site Persistence: NONE Backup Session Timeout: 0 Empty Down Response: DISABLED Multi IP Response: DISABLED Dynamic Weights: DISABLED Cname Flag: DISABLED Effective State Considered: NONE 1) site11_svc(10.100.00.00: 80)- HTTP State: UP Weight: 1 Dynamic Weight: 0 Cumulative Weight: 1 Effective State: UP Threshold : BELOW Location: Europe.GB.17.London.UK-East.ISP-UK 2) site12_svc(10.101.00.100: 80)- HTTP State: UP Weight: 1 Dynamic Weight: 0 Cumulative Weight: 1 Effective State: UP Threshold : BELOW Location: North America.US.TX.Dallas.US-East.ISP-US 3) site13_svc(10.102.00.200: 80)- HTTP State: UP Weight: 1 Dynamic Weight: 0 Cumulative Weight: 1 Effective State: UP Threshold : BELOW Location: North America.US.NJ.Salem.US-Mid.ISP-US 1) www.gslbindia.com TTL: 5 secn Cookie Timeout: 0 min Site domain TTL: 3600 sec Done
354
355
Chapter 16
Rate Limiting
356
Appendix A
Documentation Library
Topics:
Release Notes Quick Start Guides Configuration Guides Reference Guides This appendix contains links to various NetScaler guides. You can either click the respective document ID to open the PDF version of the guide, or use the ID to search the guide in the Citrix Knowledge Center website available at http:// support.citrix.com. To search the guide on Citrix Knowledge Center website 1. Open the http://support.citrix.com link in a web browser. 2. Type the document ID in the Knowledge Center search text box and click Search. 3. Select the appropriate link from the search results.
357
Appendix A
Documentation Library
Release Notes
Title Citrix NetScaler Release Notes Document ID CTX132356
CTX132784 CTX132783
358
Configuration Guides
Title Citrix NetScaler Administration Guide Citrix NetScaler AppExpert Guide Citrix NetScaler Application Optimization Guide Citrix NetScaler Application Security Guide Citrix NetScaler Clustering Guide Citrix Application Firewall Guide Citrix NetScaler Getting Started Guide Citrix Hardware Installation and Setup Guide Citrix NetScaler Migration Guide Citrix NetScaler Networking Guide Citrix NetScaler Policy Configuration and Reference Guide Citrix NetScaler SDX Administration Citrix NetScaler Traffic Management Guide Citrix NetScaler VPX Getting Started Guide Document ID CTX132357 CTX132358 CTX132361 CTX132366 CTX132840 CTX132360 CTX132368 CTX132365 CTX132364 CTX132369 CTX132362 CTX132782 CTX132359 CTX132363
Reference Guides
Title Citrix NetScaler Command Reference Guide Citrix NetScaler Developers Guide Citrix NetScaler Glossary Citrix NetScaler Log Message Reference Citrix NetScaler SNMP OID Reference Document ID CTX132384 CTX132367 CTX132383 CTX132382 CTX132381
359
Appendix A
Documentation Library
360
Appendix B
Expressions Reference
Topics:
Default Syntax Expressions Classic Expressions The following tables list expressions and expression elements that you can use to identify specific types of data. The first table applies to default syntax expressions, in alphabetic order. The remaining tables cover the different types of classic expressions.
361
Appendix B
Expressions Reference
CLIENT.ETHER
CLIENT.INTERFACE.ID
CLIENT.INTERFACE.ID.EQ("id")
362
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Expressions for Numeric Client and Server Data on page 257. Compound Operations for Numbers on page 85. Operates on the IP protocol data associated with the current packet. See the other CLIENT.IP prefixes in this table. Prefixes for IPV4 Addresses and IP Subnets on page 250 . Operations for IPV4 Addresses on page 251. Compound Operations for Numbers on page 85.
CLIENT.IP
CLIENT.IP.DST
CLIENT.IP.SRC
Prefixes for IPV4 Addresses and IP Subnets on page 250 . Operations for IPV4 Addresses on page 251. Compound Operations for Numbers on page 85.
CLIENT.IPV6
Operates on IPv6 protocol data. See the other CLIENT.IPV6 prefixes in this table. Expression Prefixes for IPv6 Addresses on page 253. Operations for IPV6 Prefixes on page 254.
CLIENT.IPV6.DST
CLIENT.IPV6.SRC
Expression Prefixes for IPv6 Addresses on page 253. Operations for IPV6 Prefixes on page 254.
CLIENT.SSL
Operates on the SSL protocol data for the current packet. See the other CLIENT.SSL prefixes in this table.
363
Appendix B
Expressions Reference
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Prefixes for Numeric Data in SSL Certificates on page 242. Compound Operations for Numbers on page 85.
CLIENT.SSL.CIPHER_BITS
CLIENT.SSL.CIPHER_EXPORTA BLE
Prefixes for Text-Based SSL and Certificate Data on page 242. Booleans in Compound Expressions on page 82.
CLIENT.SSL.CLIENT_CERT
Expressions for SSL Certificates on page 243. Expressions for SSL Certificate Dates on page 167.
CLIENT.SSL.IS_SSL
Prefixes for Text-Based SSL and Certificate Data on page 242. Booleans in Compound Expressions on page 82.
CLIENT.SSL.VERSION
Prefixes for Numeric Data in SSL Certificates on page 242. Compound Operations for Numbers on page 85.
CLIENT.TCP
Operates on TCP protocol data. See the other CLIENT.TCP prefixes in this table. Expressions for TCP, UDP, and VLAN Data on page 225. Compound Operations for Numbers on page 85.
CLIENT.TCP.PAYLOAD( integer )
Expressions for TCP, UDP, and VLAN Data on page 225. Default Syntax Expressions: Evaluating Text on page 107.
364
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Operates on the UDP protocol data associated with the current packet. See the other CLIENT.UDP prefixes in this table. Expressions for TCP, UDP, and VLAN Data on page 225. Default Syntax Expressions: Evaluating Text on page 107.
CLIENT.UDP
CLIENT.UDP.DNS.DOMAIN
Expressions for TCP, UDP, and VLAN Data on page 225. Booleans in Compound Expressions on page 82.
CLIENT.UDP.DNS. [IS_AAAAREC | IS_ANYREC | IS_AREC | IS_CNAMEREC | IS_MXREC | IS_NSREC | IS_PTRREC | IS_SOAREC | IS_SRVREC] CLIENT.UDP.[DSTPORT | SRCPORT]
Expressions for TCP, UDP, and VLAN Data on page 225. Booleans in Compound Expressions on page 82. Expressions for TCP, UDP, and VLAN Data on page 225. Compound Operations for Numbers on page 85.
CLIENT.VLAN
Operates on the VLAN through which the current packet entered the NetScaler. See the other CLIENT.VLAN prefixes in this table. Expressions for TCP, UDP, and VLAN Data on page 225. Compound Operations for Numbers on page 85.
CLIENT.VLAN.ID
HTTP.REQ
Operates on HTTP requests. See the other HTTP.REQ prefixes in this table.
365
Appendix B
Expressions Reference
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Expression Prefixes for Text in HTTP Requests and Responses on page 110. Basic Operations on Text on page 141.
HTTP.REQ.BODY(integer)
HTTP.REQ.CACHE_CONTROL
Prefixes for Cache-Control Headers on page 202. Operations for Cache-Control Headers on page 202.
HTTP.REQ.CONTENT_LENGTH
Expressions for HTTP Status Codes and Numeric HTTP Payload Data Other Than Dates on page 207. Compound Operations for Numbers on page 85.
HTTP.REQ.COOKIE
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
HTTP.REQ.DATE
Format of Dates and Times in an Expression on page 160. Expressions for HTTP Request and Response Dates on page 179. Default Syntax Expressions: Evaluating Text on page 107. Compound Operations for Numbers on page 85. Operations for HTTP Headers on page 198.
HTTP.REQ.HEADER("header_name" )
Expression Prefixes for Text in HTTP Requests and Responses on page 110. Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198.
366
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Expression Prefixes for Text in HTTP Requests and Responses on page 110. Expression Prefixes for Text in HTTP Requests and Responses on page 110. Basic Operations on Text on page 141.
HTTP.REQ.HOSTNAME.[DOMAIN | Server]
HTTP.REQ.HOSTNAME.EQ("hostnam e")
Expression Prefixes for Text in HTTP Requests and Responses on page 110. Booleans in Compound Expressions on page 82. Basic Operations on Expression Prefixes on page 80.
HTTP.REQ.HOSTNAME.PORT
Expression Prefixes for Text in HTTP Requests and Responses on page 110. Compound Operations for Numbers on page 85.
HTTP.REQ.IS_VALID
Returns TRUE if the HTTP request is properly formed. See Booleans in Compound Expressions on page 82. Expression Prefixes for Text in HTTP Requests and Responses on page 110. Basic Operations on Text on page 141. Complex Operations on Text on page 146.
HTTP.REQ.METHOD
HTTP.REQ.TRACKING
Returns the HTTP body tracking mechanism. See the descriptions of other HTTP.REQ.TRACKING prefixes in this table.
367
Appendix B
Expressions Reference
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Returns TRUE or FALSE. See Booleans in Compound Expressions on page 82. Obtains the HTTP URL object from the request and sets the text mode to URLENCODED by default. See Expression Prefixes for Text in HTTP Requests and Responses on page 110.
HTTP.REQ.URL.[CVPN_ENCODE | HOSTNAME | HOSTNAME.DOMAIN | SERVER | PATH | PATH_AND_QUERY | PROTOCOL | QUERY | SUFFIX | VERSION] HTTP.REQ.URL.HOSTNAME.EQ("hos tname")
Expression Prefixes for Text in HTTP Requests and Responses on page 110. Basic Operations on Text on page 141. Complex Operations on Text on page 146. Expression Prefixes for Text in HTTP Requests and Responses on page 110. Booleans in Compound Expressions on page 82.
HTTP.REQ.URL.HOSTNAME.PORT
Expression Prefixes for Text in HTTP Requests and Responses on page 110. Compound Operations for Numbers on page 85.
HTTP.REQ.URL.PATH.IGNORE_ EMPTY_ELEMENTS
Ignores spaces in the data. See the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Ignores spaces in the data. See the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Expression Prefixes for Text in HTTP Requests and Responses on page 110. Expression Prefixes for Text in HTTP Requests and Responses on page 110.
HTTP.REQ.URL.QUERY.IGNORE _EMPTY_ELEMENTS
HTTP.REQ.USER.IS_MEMBER_OF
HTTP.REQ.USER.NAME
368
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Expression Prefixes for Text in HTTP Requests and Responses on page 110. Operates on the major or minor HTTP version string. See Expression Prefixes for Text in HTTP Requests and Responses on page 110 and Compound Operations for Numbers on page 85. Operates on HTTP responses. Expression Prefixes for Text in HTTP Requests and Responses on page 110 Basic Operations on Text on page 141. Complex Operations on Text on page 146.
HTTP.REQ.VERSION
HTTP.REQ.VERSION.[MAJOR | MINOR]
HTTP.RES HTTP.RES.BODY(integer)
HTTP.RES.CACHE_CONTROL
Prefixes for Cache-Control Headers on page 202. Operations for Cache-Control Headers on page 202.
HTTP.RES.CONTENT_LENGTH
Expression Prefixes for Text in HTTP Requests and Responses on page 110. Operations for HTTP Headers on page 198. Compound Operations for Numbers on page 85.
HTTP.RES.DATE
Format of Dates and Times in an Expression on page 160. Expressions for HTTP Request and Response Dates on page 179. Expression Prefixes for Text in HTTP Requests and Responses on page 110. Compound Operations for Numbers on page 85. Operations for HTTP Headers on page 198.
369
Appendix B
Expressions Reference
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Expression Prefixes for Text in HTTP Requests and Responses on page 110. Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198.
HTTP.RES.HEADER("header_name" )
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198.
HTTP.RES.IS_VALID
Returns TRUE if the HTTP response is properly formed. See Booleans in Compound Expressions on page 82. Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
HTTP.RES.SET_COOKIE
HTTP.RES.SET_COOKIE.COOKIE("n ame")
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
HTTP.RES.SET_COOKIE.COOKIE.EX PIRES
Obtains the Expires field of the cookie as a date string. The value of the Expires attribute can be operated upon as a time object. If multiple Expires fields are present, this expression operates on the
370
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions first one. If the Expires attribute is absent, a string of length zero is returned. Also see: Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107. Compound Operations for Numbers on page 85.
Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Prefixes for HTTP Headers on page 191. Compound Operations for Numbers on page 85. Prefixes for HTTP Headers on page 191. Default Syntax Expressions: Evaluating Text on page 107. Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107. Compound Operations for Numbers on page 85.
HTTP.RES.SET_COOKIE.COOKIE.VE RSION
371
Appendix B
Expressions Reference
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Prefixes for HTTP Headers on page 191. Booleans in Compound Expressions on page 82. Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
HTTP.RES.SET_COOKIE.EXISTS("n ame")
HTTP.RES.SET_COOKIE2
HTTP.RES.SET_COOKIE2.COOKIE(" name")
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
HTTP.RES.SET_COOKIE2.COOKIE.E XPIRES
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107. Compound Operations for Numbers on page 85.
Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110.
372
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions See also Default Syntax Expressions: Evaluating Text on page 107 and Compound Operations for Numbers on page 85.
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
HTTP.RES.SET_COOKIE2.COOKIE.D OMAIN
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107.
HTTP.RES.SET_COOKIE2.COOKIE.E XPIRES
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107. Compound Operations for Numbers on page 85.
HTTP.RES.SET_COOKIE2.COOKIE.V ERSION
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Default Syntax Expressions: Evaluating Text on page 107. Compound Operations for Numbers on page 85.
HTTP.RES.SET_COOKIE2.EXISTS(" name")
Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198. Booleans in Compound Expressions on page 82.
373
Appendix B
Expressions Reference
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Expression Prefixes for Text in HTTP Requests and Responses on page 110. Compound Operations for Numbers on page 85.
HTTP.RES.STATUS
HTTP.RES.STATUS_MSG
Expression Prefixes for Text in HTTP Requests and Responses on page 110. Returns the HTTP body tracking mechanism. See the descriptions of other HTTP.REQ.TRACKING prefixes in this table. Returns TRUE or FALSE. See Booleans in Compound Expressions on page 82. Prefixes for HTTP Headers on page 191. Operations for HTTP Headers on page 198.
HTTP.RES.TRACKING
HTTP.RES.VERSION
Expression Prefixes for Text in HTTP Requests and Responses on page 110. Operates on the major or minor HTTP version string. See Expression Prefixes for Text in HTTP Requests and Responses on page 110 and Compound Operations for Numbers on page 85. Designates an expression that refers to the server. This is the starting point for access into parameters such as Ether and SSL. See the other SERVER prefixes in this table. Operates on the ethernet protocol data associated with the current packet. See the other SERVER prefixes in this table. Prefixes for MAC Addresses on page 256. Prefixes for MAC Addresses on page 256.
HTTP.RES.VERSION.[MAJOR | MINOR]
SERVER
SERVER.ETHER
SERVER.ETHER.DSTMAC
374
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Designates an expression that refers to the ID of the network interface that received the current packet of data. See the other SERVER.INTERFACE prefixes in this table. Returns Boolean TRUE if the interface's ID matches the ID that is passed as the argument. For example: SERVER.INTERFACE.ID.EQ("LA/1") See Booleans in Compound Expressions on page 82.
SERVER.INTERFACE
SERVER.INTERFACE.ID.EQ("id")
Expressions for Numeric Client and Server Data on page 257. Compound Operations for Numbers on page 85. Operates on the IP protocol data associated with the current packet. See the other SERVER.IP prefixes in this table. Prefixes for IPV4 Addresses and IP Subnets on page 250. Operations for IPV4 Addresses on page 251. Compound Operations for Numbers on page 85.
SERVER.IP.[DST | SRC]
SERVER.IPV6
Operates on IPv6 protocol data. See the other SERVER.IPV6 prefixes in this table. Expression Prefixes for IPv6 Addresses on page 253. Operations for IPV6 Prefixes on page 254.
SERVER.IPV6.DST
SERVER.IPV6.SRC
Expression Prefixes for IPv6 Addresses on page 253. Operations for IPV6 Prefixes on page 254.
375
Appendix B
Expressions Reference
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Operates on TCP protocol data. See the other CLIENT.TCP prefixes in this table. Expressions for TCP, UDP, and VLAN Data on page 225. Compound Operations for Numbers on page 85.
SERVER.TCP
SERVER.VLAN
Operates on the VLAN through which the current packet entered the NetScaler. See the other SERVER.VLAN prefixes in this table. Expressions for TCP, UDP, and VLAN Data on page 225. Compound Operations for Numbers on page 85.
SERVER.VLAN.ID
SYS
Designates an expression that refers to the NetScaler itself, not to the client or server.. See the other SYS prefixes in this table. Classic Expressions in Default Syntax Expressions on page 99. Booleans in Compound Expressions on page 82.
SYS.EVAL_CLASSIC_EXPR(cla ssic_expression)
HTTP Callouts.
Rate Limiting. Expressions for the NetScaler System Time on page 161. Compound Operations for Numbers on page 85.
376
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Expressions for the NetScaler System Time on page 161. Booleans in Compound Expressions on page 82. Compound Operations for Numbers on page 85.
SYS.TIME.[DAY | HOURS | MINUTES | MONTH | RELATIVE_BOOT | RELATIVE_NOW SECONDS | WEEKDAY | YEAR] VPN.BASEURL.[CVPN_DECODE | CVPN_ENCODE | HOSTNAME | HOSTNAME.DOMAIN | HOSTNAME.SERVER | PATH | PATH_AND_QUERY | PROTOCOL | QUERY | SUFFIX] VPN.BASEURL.HOSTNAME.EQ("host name")
Expressions for the NetScaler System Time on page 161. Compound Operations for Numbers on page 85. Expression Prefixes for VPNs and Clientless VPNs on page 130.
Expression Prefixes for VPNs and Clientless VPNs on page 130. Booleans in Compound Expressions on page 82.
VPN.BASEURL.HOSTNAME.PORT
Expression Prefixes for VPNs and Clientless VPNs on page 130. Compound Operations for Numbers on page 85.
VPN.BASEURL.PATH.IGNORE_EMPTY _ELEMENTS
Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110.
VPN.BASEURL.QUERY.IGNORE_EMPT Y_ELEMENTS
377
Appendix B
Expressions Reference
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Expression Prefixes for VPNs and Clientless VPNs on page 130. Expression Prefixes for VPNs and Clientless VPNs on page 130.
VPN.CLIENTLESS_BASEURL
VPN.CLIENTLESS_BASEURL. [CVPN_DECODE | CVPN_ENCODE | HOSTNAME | HOSTNAME.DOMAIN | HOSTNAME.SERVER | PATH | PATH_AND_QUERY | PROTOCOL | QUERY | SUFFIX] VPN.CLIENTLESS_BASEURL.HOSTNA ME.EQ("hostname")
Expression Prefixes for VPNs and Clientless VPNs on page 130. Booleans in Compound Expressions on page 82.
VPN.CLIENTLESS_BASEURL.HOSTNA ME.PORT
Expression Prefixes for VPNs and Clientless VPNs on page 130. Compound Operations for Numbers on page 85.
VPN.CLIENTLESS_BASEURL.PATH.I GNORE_EMPTY_ELEMENTS
Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Expression Prefixes for VPNs and Clientless VPNs on page 130. Expression Prefixes for VPNs and Clientless VPNs on page 130.
VPN.CLIENTLESS_BASEURL.QUERY. IGNORE_EMPTY_ELEMENTS
VPN.CLIENTLESS_HOSTURL
VPN.CLIENTLESS_HOSTURL. [CVPN_DECODE | CVPN_ENCODE | HOSTNAME | HOSTNAME.DOMAIN | HOSTNAME.SERVER | PATH | PATH_AND_QUERY | PROTOCOL | QUERY | SUFFIX]
378
Expression Prefix
Links to Relevant Information, with Applicable Notes and Operator Descriptions Expression Prefixes for VPNs and Clientless VPNs on page 130. Booleans in Compound Expressions on page 82.
VPN.CLIENTLESS_HOSTURL.HOSTNA ME.EQ("hostname")
VPN.CLIENTLESS_HOSTURL.HOSTNA ME.PORT
Expression Prefixes for VPNs and Clientless VPNs on page 130. Compound Operations for Numbers on page 85.
VPN.CLIENTLESS_HOSTURL.PATH.I GNORE_EMPTY_ELEMENTS
Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Ignores spaces in the data. For an example, see the table Expression Prefixes for Text in HTTP Requests and Responses on page 110. Expression Prefixes for VPNs and Clientless VPNs on page 130. Expression Prefixes for VPNs and Clientless VPNs on page 130. Expression Prefixes for VPNs and Clientless VPNs on page 130. Booleans in Compound Expressions on page 82.
VPN.CLIENTLESS_HOSTURL.QUERY. IGNORE_EMPTY_ELEMENTS
VPN.HOST
VPN.HOST.[DOMAIN | Server]
VPN.HOST.EQ("hostname")
VPN.HOST.PORT
Expression Prefixes for VPNs and Clientless VPNs on page 130. Default Syntax Expressions: Evaluating Text on page 107. Compound Operations for Numbers on page 85.
379
Appendix B
Expressions Reference
Classic Expressions
The following tables provide a complete list of NetScaler classic expressions. In the table of operators, the result type of each operator is shown at the beginning of the description. In the other tables, the level of each expression is shown at the beginning of the description. For named expressions, each expression is shown as a whole.
Operators
Expression Element == Definition Boolean. Returns TRUE if the current expression equals the argument. For text operations, the items being compared must exactly match one another. For numeric operations, the items must evaluate to the same number. != Boolean. Returns TRUE if the current expression does not equal the argument. For text operations, the items being compared must not exactly match one another. For numeric operations, the items must not evaluate to the same number. CONTAINS Boolean. Returns TRUE if the current expression contains the string that is designated in the argument. NOTCONTAINS Boolean. Returns TRUE if the current expression does not contain the string that is designated in the argument. CONTENTS Text. Returns the contents of the current expression.
380
Definition Boolean. Returns TRUE if the item designated by the current expression exists.
NOTEXISTS
Boolean. Returns TRUE if the item designated by the current expression does not exist.
>
Boolean. Returns TRUE if the current expression evaluates to a number that is greater than the argument.
<
Boolean. Returns TRUE if the current expression evaluates to a number that is less than the argument.
>=
Boolean. Returns TRUE if the current expression evaluates to a number that is greater than or equal to the argument.
<=
Boolean. Returns TRUE if the current expression evaluates to a number that is less than or equal to the argument.
General Expressions
Expression Element REQ Definition Flow Type. Operates on incoming (or request) packets. REQ.HTTP Protocol
381
Appendix B
Expressions Reference
Expression Element
REQ.HTTP.METHOD
REQ.HTTP.URL
REQ.HTTP.URLTOKENS
REQ.HTTP.VERSION
REQ.HTTP.HEADER
REQ.HTTP.URLLEN
REQ.HTTP.URLQUERY
REQ.HTTP.URLQUERYLEN
REQ.SSL
REQ.SSL.CLIENT.CERT
REQ.SSL.CLIENT.CERT.SUBJECT
382
REQ.SSL.CLIENT.CERT.SIGALGO
REQ.SSL.CLIENT.CERT.VERSION
REQ.SSL.CLIENT.CERT.VALIDFROM
Qualifier Designates the date before which the client certificate is not valid.
REQ.SSL.CLIENT.CERT.VALIDTO
Qualifier Designates the date after which the client certificate is not valid.
REQ.SSL.CLIENT.CERT.SERIALNUMB ER
Qualifier Designates the serial number of the client certificate. Qualifier Designates the encryption protocol used by the client.
REQ.SSL.CLIENT.CIPHER.TYPE
REQ.SSL.CLIENT.CIPHER.BITS
Qualifier Designates the number of bits used by the clients SSL key.
REQ.SSL.CLIENT.SSL.VERSION
REQ.TCP
383
Appendix B
Expressions Reference
REQ.TCP.DESTPORT
REQ.IP
REQ.IP.SOURCEIP
REQ.IP.DESTIP
RES
RES.HTTP
RES.HTTP.VERSION
RES.HTTP.HEADER
RES.HTTP.STATUSCODE
RES.TCP 384
Protocol
Expression Element
RES.TCP.SOURCEPORT
RES.TCP.DESTPORT
RES.IP
RES.IP.SOURCEIP
Qualifier Designates the source IP of the outgoing packet. This can be in IPv4 or IPv6 format. For example: add expr exp3 sourceip == 10.102.32.123 netmask 255.255.255.0 && destip == 2001::23/120.
RES.IP.DESTIP
385
Appendix B
Expressions Reference
Definition Checks whether the client is running the designated personal firewall program and version. Checks whether the client is not running the designated personal firewall program and version. Checks whether the client is running the designated internet security program and version. Checks whether the client is not running the designated internet security program and version. Checks whether the client is running the designated anti-spam program and version. Checks whether the client is not running the designated anti-spam program and version.
Network-Based Expressions
Expression REQ Definition Flow Type. Operates on incoming, or request, packets. REQ.VLANID Qualifier. Operates on the virtual LAN (VLAN) ID. REQ.INTERFACE.ID Qualifier. Operates on the ID of the designated NetScaler interface.
386
Expression REQ.INTERFACE.RXTHROUGHPUT
Definition Qualifier. Operates on the raw received packet throughput of the designated NetScaler interface.
REQ.INTERFACE.TXTHROUGHPUT
Qualifier. Operates on the raw transmitted packet throughput of the designated NetScaler interface.
REQ.INTERFACE.RXTXTHROUGHPUT
Qualifier. Operates on the raw received and transmitted packet throughput of the designated NetScaler interface.
REQ.ETHER.SOURCEMAC
REQ.ETHER.DESTMAC
RES
RES.VLANID
RES.INTERFACE.ID
RES.INTERFACE.RXTHROUGHPUT
Qualifier. Operates on the raw received packet throughput of the designated NetScaler interface.
RES.INTERFACE.TXTHROUGHPUT
Qualifier. 387
Appendix B
Expressions Reference
Expression
Definition Operates on the raw transmitted packet throughput of the designated NetScaler interface.
RES.INTERFACE.RXTXTHROUGHPUT
Qualifier. Operates on the raw received and transmitted packet throughput of the designated NetScaler interface.
RES.ETHER.SOURCEMAC
RES.ETHER.DESTMAC
Date/Time Expressions
Expression TIME Definition Qualifier. Operates on the date and time of day, GMT. DATE Qualifier. Operates on the date, GMT. DAYOFWEEK Operates on the specified day in the week, GMT.
388
Expression FS.COMMAND
Definition Qualifier. Operates on a file system command. The user can issue multiple commands on a file transfer portal. (For example, ls to list files or mkdir to create a directory). This expression returns the current action that the user is taking. Possible values: Neighbor, login, ls, get, put, rename, mkdir, rmdir, del, logout, any. Following is an example: Add authorization policy pol1 fs.command eq login && (fs.user eq administrator || fs.serverip eq 10.102.88.221 netmask 255.255.255.252) allow
FS.USER
Returns the user who is logged on to the file system. Returns the host name of the target server. In the following example, the string win2k3-88-22 is the server name: fs.server eq win2k3-88-221
FS.SERVER
FS.SERVERIP
Returns the IP address of the target server. Returns a shared root directory on the file server. If a particular folder is exposed as shared, a user can directly log on to the specified first level folder. This first level folder is called a service. For example, in the path \\hostname \SERVICEX\ETC, SERVICEX is the service. As another example, if a user accesses the file \\hostname \service1\dir1\file1.doc, FS.SERVICE will return service1. Following is an example:
FS.SERVICE
389
Appendix B
Expressions Reference
Expression
FS.DOMAIN
Returns the domain name of the target server. Returns the complete path of the file being accessed. For example, if a user accesses the file \\hostname \service1\dir1\file1.doc, FS.PATH will return \service \dir1\file1.doc. Following is an example: fs.path notcontains SSL
FS.PATH
FS.FILE
Returns the name of the file being accessed. For example, if a user accesses the file \\hostname \service1\dir1\file1.doc, FS.FILE will return file1.doc. Returns the directory being accessed. For example, if a user accesses the file \ \hostname \service1\dir1\file1.doc, FS.DIR will return \service\dir1. Returns the time at which the file was last accessed. This is one of several options that provide you with granular control over actions that the user performs. (See the following entries in this table.) Returns the time at which the file was created. Returns the time at which the file was edited. Returns the time of the most recent change in the status of the file.
FS.DIR
FS.FILE.ACCESSTIME
FS.FILE.CREATETIME
FS.FILE.MODIFYTIME
FS.FILE.WRITETIME
390
Definition Returns the file size. Returns the time at which the directory was last accessed. Returns the time at which the directory was created. Returns the time at which the directory was last modified. Returns the time at which the directory status last changed.
FS.DIR.CREATETIME
FS.DIR.MODIFYTIME
FS.DIR.WRITETIME
ns_cachecontrol_nocache
ns_cachecontrol_nostore
ns_cmpclient
ns_content_type
391
Appendix B
Expressions Reference
Expression ns_css
Definition Tests for connections with an HTTP Content-Type header that contains text/ css. Tests for HTTP connections to any URL that contains the string .aspin other words, any connection to an active server page (ASP). Tests for HTTP connections to any URL that contains the string .cfm Tests for HTTP connections to any URL that contains the string .cgiin other words, any connection to a common gateway interface (CGI) script. Tests for HTTP connections to any URL that contains the string .ex Tests for HTTP connections to any URL that contains the string .exein other words, any connection to a executable file. Tests for HTTP connections to any URL that contains the string .htx Tests for HTTP connections to any URL that does not contain the string .gifin other words, any connection to a URL that is not a GIF image. Tests for HTTP connections to any URL that does not contain the string .jpegin other words, any connection to a URL that is not a JPEG image. Tests for HTTP connections to any URL that contains the string .shtmlin other words, any connection to a server-parsed HTML page.
ns_ext_asp
ns_ext_cfm
ns_ext_cgi
ns_ext_ex
ns_ext_exe
ns_ext_htx
ns_ext_not_gif
ns_ext_not_jpeg
ns_ext_shtml
392
Definition Always returns a value of FALSE. Client is in a different geographical region from the NetScaler, as determined by the geographical region in the clients IP address. The following regions are predefined: 192.0.0.0 193.255.255.255: Multiregional 194.0.0.0 195.255.255.255: European Union 196.0.0.0 197.255.255.255: Other1 198.0.0.0 199.255.255.255: North America 200.0.0.0 201.255.255.255: Central and South America 202.0.0.0 203.255.255.255: Pacific Rim 204.0.0.0 205.255.255.255: Other2 206.0.0.0 207.255.255.255: Other3
ns_header_cookie
Tests for HTTP connections that contain a Cookie header Tests for HTTP connections that contain a Pragma: no-cache header. Tests for HTTP connections whose UserAgent header contains the string Mozilla/ 4.7in other words, any connection from a client using the Mozilla 4.7 Web browser. Tests for HTTP connections whose Content-Type header contains the string application/vnd.msexcelin other words, any connection transmitting a Microsoft Excel spreadsheet. Tests for HTTP connections whose UserAgent header contains the string MSIEin
ns_header_pragma
ns_mozilla_47
ns_msexcel
ns_msie
393
Appendix B
Expressions Reference
Expression
Definition other words, any connection from a client using any version of the Internet Explorer Web browser.
ns_msppt
Tests for HTTP connections whose Content-Type header contains the string application/vnd.ms-powerpointin other words, any connection transmitting a Microsoft PowerPoint file. Tests for HTTP connections whose Content-Type header contains the string application/vnd.mswordin other words, any connection transmitting a Microsoft Word file. Tests for HTTP connections that use any HTTP method except for GET. Returns TRUE if the average round trip time between the client and the NetScaler is more than 80 milliseconds. Returns TRUE for all traffic. Tests the URL path to see if it points to the /bin/ directory. Tests the URL path to see if it points to the CGI-BIN directory. Tests the URL path to see if it points to the /exec/ directory.
ns_msword
ns_non_get
ns_slowclient
ns_true ns_url_path_bin
ns_url_path_cgibin
ns_url_path_exec
ns_url_tokens ns_xmldata
Tests for the presence of URL tokens. Tests for the presence of XML data.
394
McAfee Antivirus
Sophos Antivirus 4
Sophos Antivirus 5
Sophos Antivirus 6
395
Appendix B
Expressions Reference
396
Appendix C
397
Appendix C
Expression Type
Sample Expressions Control").contains("m ust-revalidate") http.res.header("Cach eControl").contains("p roxy-revalidate") http.res.header("Cach eControl").contains("m ax-age")
http.req.header("myHe ader").exists http.res.header("myHe ader").exists http.req.url.contains (".html") http.req.url.contains (".cgi") http.req.url.contains (".asp") http.req.url.contains (".exe") http.req.url.contains (".cfm") http.req.url.contains (".ex") http.req.url.contains (".shtml") http.req.url.contains (".htx") http.req.url.contains ("/cgi-bin/") http.req.url.contains ("/exec/") http.req.url.contains ("/bin/")
Look for a particular file type in an HTTP request based on the file extension.
398
Expression Type Look for anything that is other than a particular file type in an HTTP request.
Sample Expressions http.req.url.contains (".gif").not http.req.url.contains (".jpeg").not http.res.header("Cont entType").contains("text ") http.res.header("Cont entType").contains("appl ication/msword") http.res.header("Cont entType").contains("vnd. ms-excel") http.res.header("Cont entType").contains("appl ication/vnd.mspowerpoint") http.res.header("Cont entType").contains("text /css") http.res.header("Cont entType").contains("text /xml") http.res.header("Cont entType").contains("imag e/")
Check the type of file that is being sent in an HTTP response based on the Content-Type header.
Check whether this response contains an expiration header. Check for a Set-Cookie header in a response.
http.res.header("Expi res").exists
http.res.header("SetCookie").exists
399
Appendix C
Check if the first 1024 bytes of the body of a request starts with the string some text.
The following table shows examples of policy configurations and bindings for commonly used functions. Table C-2. Examples of Default Syntax Expressions and Policies Purpose Use the rewrite feature to replace occurrences of http:// with https:// in the body of an HTTP response. Example add rewrite action httpRewriteAction replace_all http.res.body(50000) "\"https://\"" pattern http:// add rewrite policy demo_rep34312 "http.res.body(50000) .contains(\"http:// \")" httpRewriteAction Replace all occurrences of abcd with 1234 in the first 1000 bytes of the HTTP body. add rewrite action abcdTo1234Action replace_all "http.req.body(1000)" "\"1234\"" -pattern abcd add rewrite policy abcdTo1234Policy
400
Purpose
Example "http.req.body(1000). contains(\"abcd\")" abcdTo1234Action bind rewrite global abcdTo1234Policy 100 END -type REQ_OVERRIDE
Downgrade the HTTP version to 1.0 to prevent the server from chunking HTTP responses.
add rewrite action downgradeTo1.0Action replace http.req.version.mino r "\"0\"" add rewrite policy downgradeTo1.0Policy "http.req.version.min or.eq(1)" downgradeTo1.0Action bind lb vserver myLBVserver policyName downgradeTo1.0Policy -priority 100 gotoPriorityExpressio n NEXT -type REQUEST
Remove references to the HTTP or HTTPS protocol in all responses, so that if the user's connection is HTTP, the link is opened by using HTTP, and if the user's connection is HTTPS, the link is opened by using HTTPS.
add rewrite action remove_http_https replace_all "http.res.body(100000 0).set_text_mode(igno recase)" "\"//\"" pattern "re~https?://| HTTPS?://~" add rewrite policy remove_http_https true remove_http_https bind lb vserver test_vsvr -policyName remove_http_https priority 20 -
401
Appendix C
Purpose
Rewrite instances of http:// to https:// in all URLs. This policy uses the responder functionality.
add responder action httpToHttpsAction redirect "\"https:// \" + http.req.hostname + http.req.url" bypassSafetyCheck YES add responder policy httpToHttpsPolicy "! CLIENT.SSL.IS_SSL" httpToHttpsAction bind responder global httpToHttpsPolicy 1 END -type OVERRIDE
Modify a URL to redirect from URL A to URL B. In this example, file5.html is appended to the path. This policy uses the responder functionality.
add responder action appendFile5Action redirect "\"http://\" + http.req.hostname + http.req.url + \"/ file5.html\"" bypassSafetyCheck YES add responder policy appendFile5Policy "http.req.url.eq(\"/ testsite\")" appendFile5Action bind responder global appendFile5Policy 1 END -type OVERRIDE
add rewrite action act_external_to_inter nal REPLACE 'http.req.hostname.se rver' '"www.my.host.com"' add rewrite policy pol_external_to_inter nal
402
Purpose
Example 'http.req.hostname.se rver.eq("www.external .host.com")' act_external_to_inter nal bind rewrite global pol_external_to_inter nal 100 END -type REQ_OVERRIDE
Redirect requests to www.example.com that have a query string to www.Webn.example.com. The value n is derived from a server parameter in the query string, for example, server=5.
add rewrite action act_redirect_query REPLACE q#http.req.header("Ho st").before_str(".exa mple.com")' '"Web" + http.req.url.query.va lue("server")# add rewrite policy pol_redirect_query q#http.req.header("Ho st").eq("www.example. com") && http.req.url.contains ("?")' act_redirect_query#
add ns limitSelector ip_limit_selector http.req.url "client.ip.src" add ns limitIdentifier ip_limit_identifier threshold 4 timeSlice 3600 -mode request_rate limitType smooth selectorName ip_limit_selector add responder action my_Web_site_redirect_ action redirect
403
Appendix C
Purpose
Example "\"http:// www.mycompany.com/\"" add responder policy ip_limit_responder_po licy "http.req.url.contain s(\"myasp.asp\") && sys.check_limit(\"ip_ limit_identifier\")" my_Web_site_redirect_ action bind responder global ip_limit_responder_po licy 100 END -type default
Check the client IP address but pass the request without modifying the request.
add rewrite policy check_client_ip_polic y 'HTTP.REQ.HEADER("xforwardedfor").EXISTS || HTTP.REQ.HEADER("clie nt-ip").EXISTS' NOREWRITE bind rewrite global check_client_ip_polic y 100 END
add rewrite action del_x_forwarded_for delete_http_header xforwarded-for add rewrite action del_client_ip delete_http_header client-ip add rewrite policy check_x_forwarded_for _policy 'HTTP.REQ.HEADER("xforwarded-
404
Purpose
Example for").EXISTS' del_x_forwarded_for add rewrite policy check_client_ip_polic y 'HTTP.REQ.HEADER("cli ent-ip").EXISTS' del_client_ip add rewrite action insert_ns_client_head er insert_http_header NS-Client 'CLIENT.IP.SRC' add rewrite policy insert_ns_client_poli cy 'HTTP.REQ.HEADER("xforwardedfor").EXISTS || HTTP.REQ.HEADER("clie nt-ip").EXISTS' insert_ns_client_head er bind rewrite global check_x_forwarded_for _policy 100 200 bind rewrite global check_client_ip_polic y 200 300 bind rewrite global insert_ns_client_poli cy 300 END
Remove old headers from a request, insert an NS-Client header, and then modify the insert header action so that the value of the inserted header contains the client IP values from the old headers and the NetScalers connection IP address.
add rewrite action del_x_forwarded_for delete_http_header xforwarded-for add rewrite action del_client_ip delete_http_header client-ip
405
Appendix C
Purpose Note that this example repeats the previous example, with the exception of the final set rewrite action.
Example add rewrite policy check_x_forwarded_for _policy 'HTTP.REQ.HEADER("xforwardedfor").EXISTS' del_x_forwarded_for add rewrite policy check_client_ip_polic y 'HTTP.REQ.HEADER("cli ent-ip").EXISTS' del_client_ip add rewrite action insert_ns_client_head er insert_http_header NS-Client 'CLIENT.IP.SRC' add rewrite policy insert_ns_client_poli cy 'HTTP.REQ.HEADER("xforwardedfor").EXISTS || HTTP.REQ.HEADER("clie nt-ip").EXISTS' insert_ns_client_head er bind rewrite global check_x_forwarded_for _policy 100 200 bind rewrite global check_client_ip_polic y 200 300 bind rewrite global insert_ns_client_poli cy 300 END set rewrite action insert_ns_client_head er -stringBuilderExpr 'HTTP.REQ.HEADER("xforwarded-
406
Purpose
Example for").VALUE(0) + " " + HTTP.REQ.HEADER("clie nt-ip").VALUE(0) + " " + CLIENT.IP.SRC' bypassSafetyCheck YES
407
Appendix C
408
Appendix D
409
Appendix D
Citrix NetScaler Policy Configuration and Reference Guide 11. In the Action drop-down menu, choose the action act_external_to_internal. 12. In the Expression editor, construct the following expression: HTTP.REQ.HOSTNAME.SERVER.EQ("www.example.com") 13. Bind your new policy globally.
Redirecting a Query
This example describes how to create a rewrite action and rewrite policy that redirects a query to the proper URL. The example assumes that the request contains a Host header set to www.example.com and a GET method with the string /query.cgi? server=5. The redirect extracts the domain name from the host header and the number from the query string, and redirects the users query to the server Web5.example.com, where the rest of the users query is processed. Note: Although the following commands appears on multiple lines, you should enter them on a single line without line breaks.
411
Appendix D
To create the appropriate Rewrite action by using the NetScaler command line
At the NetScaler command prompt, type one of the following commands to either remove the Accept Encoding header and prevent response compression or remove the Content Location header: w add rewrite action "act_remove-ae" delete_http_header "Accept-Encoding" 412
Citrix NetScaler Policy Configuration and Reference Guide w add rewrite action "act_remove-cl" delete_http_header "Content-Location"
To create the appropriate Rewrite policy by using the NetScaler command line
At the NetScaler command prompt, type one of the following commands to remove either the Accept Encoding header or the Content Location header: w add rewrite policy "pol_remove-ae" true "act_remove-ae" w add rewrite policy "pol_remove-cl" true "act_remove-cl"
To modify directory-level HTTP requests to include the default home page by using the command line
w To create a Rewrite action named action-default-homepage that modifies URLs that end in a forward slash to include the default home page index.html, type: add rewrite action "action-default-homepage" replace q#http.req.url.path "/" "/ index.html"# w To create a Rewrite policy named policy-default-homepage that detects connections to your home page and applies your new action, type: add rewrite policy "policy-default-homepage" q#http.req.url.path.EQ("/") "actiondefault-homepage"# w Globally bind your new policy to put it into effect.
413
Appendix D
414
Appendix E
415
Appendix E
NetScaler solution for converting a URL add responder action act1 redirect '"/ u/"+HTTP.REQ.URL.AFTER_STR("/~")' -bypassSafetyCheck yes add responder policy pol1 'HTTP.REQ.URL.STARTSWITH("/~") && HTTP.REQ.URL.LENGTH.GT(2)' act1 bind responder global pol1 100
Apache mod_rewrite solution for enforcing a particular host name for sites running on port 80 RewriteCond %{HTTP_HOST} RewriteCond %{HTTP_HOST} RewriteRule ^/(.*) !^www.example.com !^$ http://www.example.com/$1 [L,R]
NetScaler solution for enforcing a particular host name for sites running on a port other than 80 add responder action act1 redirect '"http:// www.example.com:"+CLIENT.TCP.DSTPORT+HTTP.REQ.URL' bypassSafetyCheck yes 416
Citrix NetScaler Policy Configuration and Reference Guide add responder policy pol1 '! HTTP.REQ.HOSTNAME.CONTAINS("www.example.com")&&! HTTP.REQ.HOSTNAME.EQ("")&&! HTTP.REQ.HOSTNAME.PORT.EQ(80)&&HTTP.REQ.HOSTNAME.CONTAINS("exampl e.com")' act1 bind responder global pol1 100 END NetScaler solution for enforcing a particular host name for sites running on port 80 add responder action act1 redirect '"http:// www.example.com"+HTTP.REQ.URL' -bypassSafetyCheck yes add responder policy pol1 '! HTTP.REQ.HOSTNAME.CONTAINS("www.example.com")&&! HTTP.REQ.HOSTNAME.EQ("")&&HTTP.REQ.HOSTNAME.PORT.EQ(80)&&HTTP.REQ .HOSTNAME.CONTAINS("example.com")' act1 bind responder global pol1 100 END
/e/www/
[R]
NetScaler solution for moving the document root add responder action act1 redirect '"/e/www/"' -bypassSafetyCheck yes add responder policy pol1 'HTTP.REQ.URL.EQ("/")' act1 bind responder global pol1 100 NetScaler solution for moving the document root and appending path information to the request add responder action act1 redirect '"/e/www"+HTTP.REQ.URL' bypassSafetyCheck yes add responder policy pol1 '!HTTP.REQ.URL.STARTSWITH("/e/www/")' act1 bind responder global pol1 100 END
417
Appendix E
NetScaler solution for redirecting to another Web server (method 1) add responder action act1 redirect '"http:// newserver"+HTTP.REQ.URL' -bypassSafetyCheck yes add responder policy pol1 'HTTP.REQ.URL.REGEX_MATCH(re#^/(. +)#)' act1 bind responder global pol1 100 END NetScaler solution for redirecting to another Web server (method 2) add responder action act1 redirect '"http:// newserver"+HTTP.REQ.URL' -bypassSafetyCheck yes add responder policy pol1 'HTTP.REQ.URL.LENGTH.GT(1)' act1 bind responder global pol1 100 END
NetScaler solution for structured home directories NetScaler solution for structured home directories add rewrite action act1 replace 'HTTP.REQ.URL' HTTP.REQ.URL.AFTER_STR("~").PREFIX(1)+"/"+ HTTP.REQ.URL.AFTER_STR("~").BEFORE_STR("/") 418 '"/home/"+
Citrix NetScaler Policy Configuration and Reference Guide +"/.www"+HTTP.REQ.URL.SKIP(\'/\',1)' -bypassSafetyCheck yes add rewrite policy pol1 'HTTP.REQ.URL.PATH.STARTSWITH("/~")' act1 bind rewrite global pol1 100
NetScaler solution for redirection if a URL is wrong (method 1) add HTTPCallout Call set policy httpCallout Call -IPAddress 10.102.59.101 -port 80 hostExpr '"10.102.59.101"' -returnType BOOL -ResultExpr 'HTTP.RES.BODY(100).CONTAINS("True")' -urlStemExpr '"/cgi-bin/ file_check.cgi"' -parameters query=http.req.url.path -headers Name("ddd") add responder action act1 redirect '"http:// webserverB.com"+HTTP.REQ.URL' -bypassSafetyCheck yes add responder policy pol1 '!HTTP.REQ.HEADER("Name").EXISTS && ! SYS.HTTP_CALLOUT(call)' act1 bind responder global pol1 100 NetScaler solution for redirection if a URL is wrong (method 2) add HTTPCallout Call set policy httpCallout Call -IPAddress 10.102.59.101 -port 80 hostExpr '"10.102.59.101"' -returnType BOOL -ResultExpr 'HTTP.RES.BODY(100).CONTAINS("True")' -urlStemExpr '"/cgi-bin/ file_check.cgi"' -parameters query=http.req.url.path -headers Name("ddd") add responder action act1 respondwith '"HTTP/1.1 302 Moved Temporarily\r\nLocation: http://webserverB.com"+HTTP.REQ.URL+"\r\n \r\nHTTPCallout Used"' -bypassSafetyCheck yes add responder policy pol1 '!HTTP.REQ.HEADER("Name").EXISTS && ! 419
Appendix E
Migration of Apache mod_rewrite Rules to the Default Syntax SYS.HTTP_CALLOUT(call)' act1 bind responder global pol1 100
NetScaler solution for rewriting a URL based on the time add rewrite action act1 insert_before 'HTTP.REQ.URL.PATH.SUFFIX(\'.\',0)' '"day."' add rewrite action act2 insert_before 'HTTP.REQ.URL.PATH.SUFFIX(\'.\',0)' '"night."' add rewrite policy pol1 'SYS.TIME.WITHIN(LOCAL 07h 00m,LOCAL 18h 59m)' act1 add rewrite policy pol2 'true' act2 bind rewrite global pol1 101 bind rewrite global pol2 102
bar.html
NetScaler solution for managing a file name change in a fixed location add rewrite action act1 replace 'HTTP.REQ.URL.AFTER_STR("/ ~quux").SUBSTR("foo.html")' '"bar.html"' add rewrite policy pol1 'HTTP.REQ.URL.ENDSWITH("/~quux/ 420
Citrix NetScaler Policy Configuration and Reference Guide foo.html")' act1 bind rewrite global pol1 100 NetScaler solution for managing a file name change regardless of the base directory or query strings in the URL add rewrite action act1 replace 'HTTP.REQ.URL.PATH.SUFFIX(\'/\', 0)' '"bar.html"' Add rewrite policy pol1 'HTTP.REQ.URL.PATH.CONTAINS("foo.html")' act1 Bind rewrite global pol1 100
[R]
NetScaler solution for changing the file name and the URL displayed in the browser add responder action act1 redirect 'HTTP.REQ.URL.BEFORE_STR("foo.html")+"new.html"' bypassSafetyCheck yes add responder policy pol1 'HTTP.REQ.URL.ENDSWITH("/~quux/ old.html")' act1 bind responder global pol1 100 NetScaler solution for changing the file name and the URL displayed in the browser regardless of the base directory or query strings in the URL add responder action act1 redirect 'HTTP.REQ.URL.PATH.BEFORE_STR("old.html") +"new.html"+HTTP.REQ.URL.AFTER_STR("old.html")' bypassSafetyCheck yes add responder policy pol1 'HTTP.REQ.URL.PATH.CONTAINS("old.html")' act1 bind responder global pol1 100
421
Appendix E
422
Citrix NetScaler Policy Configuration and Reference Guide In the following examples, the Web location to be blocked is /~quux/foo/arc/, the IP addresses to be blocked are 123.45.67.8 and 123.45.67.9, and the robots name is NameOfBadRobot. Apache mod_rewrite solution for blocking a path and a User-Agent header RewriteCond %{HTTP_USER_AGENT} RewriteCond %{REMOTE_ADDR} RewriteRule ^/~quux/foo/arc/.+ ^NameOfBadRobot.* ^123\.45\.67\.[8-9]$ [F]
NetScaler solution for blocking a path and a User-Agent header add responder action act1 respondwith '"HTTP/1.1 403 Forbidden\r\n \r\n"' add responder policy pol1 'HTTP.REQ.HEADER("User_Agent").STARTSWITH("NameOfBadRobot")&&CLIE NT.IP.SRC.EQ(123.45.67.8)&&CLIENT.IP.SRC.EQ(123.45.67.9) && HTTP.REQ.URL.STARTSWITH("/~quux/foo/arc")' act1 bind responder global pol1 100
423
Appendix E
NetScaler policy for adding either .html or .php extensions to requests add HTTPCallout Call_html add HTTPCallout Call_php set policy httpCallout Call_html -IPAddress 10.102.59.101 -port 80 -hostExpr '"10.102.59.101"' -returnType BOOL -ResultExpr 'HTTP.RES.BODY(100).CONTAINS("True")' -urlStemExpr '"/cgi-bin/ file_check.cgi"' -parameters query=http.req.url+".html" set policy httpCallout Call_php -IPAddress 10.102.59.101 -port 80 -hostExpr '"10.102.59.101"' -returnType BOOL -ResultExpr 'HTTP.RES.BODY(100).CONTAINS("True")' -urlStemExpr '"/cgi-bin/ file_check.cgi"' -parameters query=http.req.url+".php" add patset pat1 bind patset pat1 .html 424
Citrix NetScaler Policy Configuration and Reference Guide bind patset pat1 .php bind patset pat1 .asp bind patset pat1 .cgi add rewrite action act1 insert_after 'HTTP.REQ.URL.PATH' '".html"' add rewrite action act2 insert_after "HTTP.REQ.URL.PATH" '".php"' add rewrite policy pol1 '!HTTP.REQ.URL.CONTAINS_ANY("pat1") && SYS.HTTP_CALLOUT(Call_html)' act1 add rewrite policy pol2 '!HTTP.REQ.URL.CONTAINS_ANY("pat1") && SYS.HTTP_CALLOUT(Call_php)' act2 bind rewrite global pol1 100 END bind rewrite global pol2 101 END
Appendix E
https://
426
Appendix F
427
Appendix F
Authentication policies
Global
For the Authentication feature, policies contain authentication schemes for different authentication methods. For example, you can configure LDAP and certificatebased authentication schemes. To determine when to apply an encryption function and add certificate information to clear text. To provide endto-end security. After a message is decrypted, the SSL feature re-encrypts clear text and uses SSL to communicate with back-end Web servers.
SSL
None
SSL policies
428
Feature
Supported Policies
Content Switching (Can use either classic or default syntax policies, but not both)
To determine what server or group of servers is responsible for serving responses, based on characteristics of an incoming request. Request characteristics include device type, language, cookies, HTTP method, content type and associated cache server.
Compression
None
w Global w Content Switching virtual server w Load Balancing virtual server w SSL Offload virtual server w Service
None
w Global w Content Switching virtual server w Load Balancing virtual server w SSL Offload virtual server
429
Appendix F
Feature
Virtual Server s
Supported Policies
w Service Protection features, SureConnect None SureConnect policies w Load Balancing virtual server w SSL Offload virtual server w Service Protection features, Priority Queuing None Priority Queuing policies w Load Balancing virtual server w SSL Offload virtual server HTML Injection None HTML Injection Policies w Global w Load Balancing virtual server w Content Switching virtual server w SSL Offload virtual server AAA - Traffic Management None Authentication, Authorization, Auditing, and Session policies w Authenticatio n virtual server (authenticati on, session, and auditing policies) w Load Balancing or Content Switching virtual server (authorizatio n and 430 To configure rules for user access to specific sessions and auditing of user access. To configure the behavior of the Priority Queuing function. To configure the behavior of the SureConnect function.
To enable the NetScaler to insert text or scripts into an HTTP response that it serves to a client.
Feature
Virtual Server s
Supported Policies
auditing policies) w Global (session and audit policies) w AAA group or user (session, auditing, and authorization policies) Cache Redirection Cache Redire ction virtual server Cache Redirection policies Map policies Cache Redirection virtual server To determine whether HTTP responses are served from a cache or an origin server. To identify characteristics of traffic and data that should or should not be admitted through the firewall. To determine how the Access Gateway performs authentication, authorization, auditing, and other functions, and to define rewrite rules for general Web access using the Access Gateway.
Application Firewall
None
Global
Access Gateway
VPN server
w AAA Global w VPN vserver w System Global w AAA Global w VPN vserver
Auditing policies
431
Appendix F
Feature
Virtual Server s
Supported Policies
w VPN vserver Session policies w VPN Global w User w User Group w VPN vserver Authorization policies w User w User Group w VPN Global w User w User Group w VPN vserver TCP Compression policies VPN Global
Traffic policies
432
Example
The following commands first create a compression action and then create a compression policy that applies the action: > add cmp action cmp-act-compress compress Done > show cmp action cmp-act-compress 1) Name: cmp-act-compress Compression Type: compress Done > add cmp pol cmp-pol-compress -rule ExpCheckIp resAction cmp-act-compress Done > show cmp pol cmp-pol-compress 1) Name: cmp-pol-compress Rule: ExpCheckIp Response action: cmp-act-compress Hits: 0 Done >
Appendix F
Citrix NetScaler Policy Configuration and Reference Guide 6. Click Create to create your new policy. 7. Click Close to return to the Policies screen for the type of policy you were creating.
Appendix F
Configuring Classic Policies and Expressions w set <featureName> policy <name> -rule <expression> -action <action> w show <featureName> policy <name>
Example
> set appfw policy GenericApplicationSSL_ 'HTTP.REQ.METHOD.EQ("get")' APPFW_DROP Done > show appfw policy GenericApplicationSSL_ Name: GenericApplicationSSL_ Rule: HTTP.REQ.METHOD.EQ("get") Profile: APPFW_DROP Hits: 0 Undef Hits: 0 Policy is bound to following entities 1) REQ VSERVER app_u_GenericApplicationSSLPortalPages PRIORITY : 100 Done
Citrix NetScaler Policy Configuration and Reference Guide IP. Evaluates the IP addresses associated with the current connection. 5. Under Qualifier, click the down arrow and choose a qualifier for your policy. The qualifier defines the type of data to be evaluated. The list of qualifiers that appears depends on which protocol you selected in step 4. The following list describes the qualifier choices for the HTTP protocol. For a complete list of protocols and qualifiers, see Classic Expressions on page 380. The following choices appear for the HTTP protocol: METHOD. Filters HTTP requests that use a particular HTTP method. URL. Filters HTTP requests for a specific Web page. URLQUERY. Filters HTTP requests that contain a particular query string. VERSION. Filters HTTP requests on the basis of the specified HTTP protocol version. HEADER. Filters on the basis of a particular HTTP header. URLLEN. Filters on the basis of the length of the URL. URLQUERY. Filters on the basis of the query portion of the URL. URLQUERYLEN. Filters on the basis of the length of the query portion of the URL only. 6. Under Operator, click the down arrow and choose the operator for your policy expression. For a complete list of choices see the Operators table in Classic Expressions on page 380. Some common operators are: Operator == Description Matches the specified value exactly or is exactly equal to the specified value. Does not match the specified value. Is greater than the specified value. Is less than the specified value. Is greater than or equal to the specified value. Is less than or equal to the specified value. Contains the specified value. 437
<=
CONTAINS
Appendix F
Operator CONTENTS
Description Returns the contents of the designated header, URL, or URL query. The specified header or query exists. Does not contain the specified value. The specified header or query does not exist.
7. If a Value text box appears, type a string or numeric value, as appropriate. For example, chose REQ as the Flow Type, HTTP as the Protocol, and HEADER as the qualifier, and then type the value of the header string in the Value field and the header type for which you want to match the string in the Header Name text box. 8. Click OK. 9. To create a compound expression, click Add. Note that the type of compounding that is done depends on the following choices in the Create Policy dialog box: Match Any Expression. The expressions are in a logical OR relationship. Match All Expressions. The expressions are in a logical AND relationship. Tabular Expressions. Click the AND, OR, and parentheses buttons to control evaluation. Advanced Free-Form. Enter the expressions components directly into the Expression field, and click the AND, OR, and parentheses buttons to control evaluation.
438
Citrix NetScaler Policy Configuration and Reference Guide w bind <featureName> global <policyName> [-priority <positive_integer>] w show <featureName> global
Example
> bind cmp global cmp-pol-compress -priority 2 Done > show cmp global 1) Policy Name: cmp-pol-compress Priority: 2 2) Policy Name: ns_nocmp_xml_ie Priority: 8700 3) Policy Name: ns_nocmp_mozilla_47 Priority: 8800 4) Policy Name: ns_cmp_mscss Priority: 8900 5) Policy Name: ns_cmp_msapp Priority: 9000 6) Policy Name: ns_cmp_content_type Priority: 10000 Done >
To bind a classic policy to a virtual server by using the NetScaler command line
At a NetScaler command prompt, type the following commands to set the parameters and verify the configuration: w bind <featureName> vserver <name> [<targetVserver>] [-policyName <string> [priority <positive_integer>] w show <featureName> policy <name>
Example
> bind lb vserver lbtemp -policyName cmp-polcompress -priority 1 Done > show lb vserver lbtemp lbtemp (10.102.29.101:80) - HTTP Type: ADDRESS State: UP Last state change was at Tue Oct 27 06:40:38 2009 (+557 ms) Time since last state change: 0 days, 02:00:40.330 Effective State: UP Client Idle Timeout: 180 sec Down state flush: ENABLED Disable Primary Vserver On Down : DISABLED Port Rewrite : DISABLED No. of Bound Services : 1 (Total) 1 439
Appendix F
Configured Method: LEASTCONNECTION Current Method: Round Robin, Reason: Bound service's state changed to UP Group: vserver-grp Mode: IP Persistence: COOKIEINSERT (version 0) Persistence Backup: SOURCEIP Persistence Mask: 255.255.255.255 Persistence Timeout: 2 min Backup Persistence Timeout: 2 min Vserver IP and Port insertion: OFF Push: DISABLED Push VServer: Push Multi Clients: NO Push Label Rule: none 1) http-one (10.102.29.252: 80) - HTTP State: UP Weight: 1 Persistence Cookie Value : NSC_wtfswfshsq=ffffffff096e03ed45525d5f4f58455e445a4a423660 1) Policy : cmp-pol-compress Priority:1 Done >
440
Note: You cannot globally bind policies for Content Switching, Cache Redirection, SureConnect, Priority Queuing, or Access Gateway Authorization. 2. In the details pane, click Global Bindings. 3. In the Bind/Unbind <feature name> Policy(s) to Global dialog box, click Insert Policy. 4. In the Policy Name column, click the name of an existing policy that you want to globally bind, or click New Policy to open the Create <feature name> Policy dialog box. 5. After you have selected the policy or created a new policy, in the Priority column, type the priority value. The lower the number, the sooner this policy is applied relative to other policies. For example, a policy assigned a priority of 10 is applied before a policy with a priority of 100. You can use the same priority for different policies. All features that use classic policies implement only the first policy that a connection matches, so policy priority is important for getting the results you intend. As a best practice, leave room to add policies by setting priorities with intervals of 50 (or 100) between each policy. 6. Click OK.
441
Appendix F
To view a classic policy and its binding information by using the NetScaler command line
At the NetScaler command prompt, type the following commands to view a classic policy and its binding information: show <featureName> policy [policyName]
Example
> show appfw policy GenericApplicationSSL_ Name: GenericApplicationSSL_ Rule: ns_only_get_adv Profile: GenericApplicationSSL_Prof1 Hits: 0 Undef Hits: 0 Policy is bound to following entities 1) REQ VSERVER app_u_GenericApplicationSSLPortalPages PRIORITY : 100 Done
Note: If you omit the policy name, all policies are listed without the binding details.
To view classic policies and policy bindings by using the configuration utility
1. In the navigation pane, expand the feature whose policies you want to view, (for example, if you want to view Application Firewall policies, expand Application Firewall), and then click Policies. 2. In the details pane, do one or more of the following: 442
Citrix NetScaler Policy Configuration and Reference Guide To view details for a specific policy, click the policy. Details appear in the Details area of the configuration pane. To view bindings for a specific policy, click the policy, and then click Show Bindings. To view global bindings, click the policy, and then click Global Bindings. Note that you cannot bind a Content Switching, Cache Redirection, SureConnect, Priority Queuing, or Access Gateway Authorization policy globally.
Appendix F
Configuring Classic Policies and Expressions w show expression [<name> | -type CLASSIC
Example
> add expression classic_ne "REQ.HTTP.URL CONTAINS www.example1.com" -comment "Checking the URL for www.example1.com" Done > show expression classic_ne 1) Name: classic_ne Expr: REQ.HTTP.URL CONTAINS www.example1.com Hits: 0 Type : CLASSIC Comment: "Checking the URL for www.example1.com" Done >
Citrix NetScaler Policy Configuration and Reference Guide Expression Name*name Client Security MessageclientSecurityMessage Commentscomment * A required parameter 4. To create the expression, do one of the following: You can choose inputs to this expression from the Named Expressions dropdown list. You can create a new expression, as described in To add an expression for a classic policy by using the configuration utility on page 436. 5. When you are done, click Close. Verify that your new expression was created by scrolling to the bottom of the Classic Expressions list to view it.
445
Appendix F
446
Appendix G
447
Appendix G
To check for a valid client certificate by using the NetScaler command line
w At a NetScaler command prompt, create an Access Gateway profile named act_current_client_cert that requires that users have a current client certificate to establish an SSL connection with the Access Gateway or NetScaler. add ssl action act_current_client_cert-clientAuth DOCLIENTAUTH -clientCert ENABLED -certHeader "header_of_client_certificate_issued_by_your_company" clientCertNotBefore ENABLED -certNotBeforeHeader "Mon, 01 Jan 2007 00:00:00 GMT" w To create an SSL policy named client_cert_policy that detects connections to the Web server that contain a query string, type: add ssl policy client_cert_policy 'REQ.SSL.CLIENT.CERT.VALIDFROM >= "Mon, 01 Jan 2008 00:00:00 GMT"' act_block_ssl w Globally bind your new policy to put it into effect. Because this SSL policy should apply to any users SSL connection unless a more specific SSL policy applies, you may want to assign a large priority value. For example, if you assign it a priority of one thousand (1000), that should ensure that other SSL policies are evaluated first, meaning that this policy will apply only to connections that do not match more specific policy criteria.
Citrix NetScaler Policy Configuration and Reference Guide obtain sensitive private information about the legitimate user or place orders using the legitimate users account. w SQL injection. A shopping cart application normally accesses a back-end database server. Unless the application performs the appropriate safety checks on the data users return in the form fields of its Web forms before it passes that information on to the SQL database, an attacker can use a Web form to inject unauthorized SQL commands into the database server. Attackers normally use this type of attack to obtain sensitive private information from the database or modify information in the database. The following configuration will protect a shopping cart application against these and other attacks.
Appendix G
Tutorial Examples of Classic Policies c. For the SQL Injection check, disable blocking, and enable learning, logging, statistics, and transformation of special characters in the Modify SQL Injection Check dialog box, General tab, Check Actions section. If you are using the command line, you configure these settings by typing the following at the prompt, and pressing ENTER: set appfw profile shopping_cart -SQLInjectionAction LEARN LOG STATS SQLInjectionTransformSpecialChars ON d. For the Credit Card check, disable blocking; enable logging, statistics, and masking of credit card numbers; and enable protection for those credit cards you accept as forms of payment. w If you are using the configuration utility, you configure blocking, logging, statistics, and masking (or x-out) in the Modify Credit Card Check dialog box, General tab, Check Actions section. You configure protection for specific credit cards in the Settings tab of the same dialog box. w If you are using the command line, you configure these settings by typing the following at the prompt, and pressing ENTER: set appfw profile shopping_cart -creditCardAction LOG STATS -creditCardXOut ON -creditCard <name> [<name>...] For <name> you substitute the name of the credit card you want to protect. For Visa, you substitute VISA. For Master Card, you substitute MasterCard. For American Express, you substitute Amex. For Discover, you substitute Discover. For Diners Club, you substitute DinersClub. For JCB, you substitute JCB. 8. Create a policy named shopping_cart that detects connections to your shopping cart application and applies the shopping_cart profile to those connections. To detect connections to the shopping cart, you examine the URL of incoming connections. If you host your shopping cart application on a separate host (a wise measure for security and other reasons), you can simply look for the presence of that host in the URL. If you host your shopping cart in a directory on a host that handles other traffic, as well, you must determine that the connection is going to the appropriate directory and/or HTML page. The process for detecting either of these is the same; you create a policy based on the following expression, and substitute the proper host or URL for <string>. REQ.HTTP.HEADER URL CONTAINS <string> If you are using the configuration utility, you navigate to the Application Firewall Policies page, click the Add... button to add a new policy, and follow the policy creation process described in To create a policy with classic expressions using the configuration utility beginning on page 201 and following. If you are using the command line, you type the following command at the prompt and press Enter: add appfw policy shopping_cart "REQ.HTTP.HEADER URL CONTAINS <string>" shopping_cart
450
Citrix NetScaler Policy Configuration and Reference Guide 9. Globally bind your new policy to put it into effect. Because you want to ensure that this policy will match all connections to the shopping cart, and not be preempted by another more general policy, you should assign a high priority to it. If you assign one (1) as the priority, no other policy can preempt this one.
To protect Web pages with cross-site scripting by using the NetScaler command line
w At the NetScaler command line, to create an advanced profile, type: add appfw profile pr_xssokay -defaults advanced w To configure the profile, type: set appfw profile pr_xssokay -startURLAction NONE -startURLClosure OFF cookieConsistencyAction LEARN LOG STATS -fieldConsistencyAction LEARN LOG STATS -crossSiteScriptingAction LEARN LOG STATS$" w Create a policy that detects connections to your scripted Web pages and applies the pr_xssokay profile, type: add appfw policy pol_xssokay "REQ.HTTP.HEADER URL CONTAINS ^\.pl\?$ || REQ.HTTP.HEADER URL CONTAINS ^\.js$" pr_xssokay w Globally bind the policy.
To protect Web pages with cross-site scripting by using the configuration utility
1. In the navigation pane, expand Application Firewall, and then click Profiles. 451
Appendix G
Tutorial Examples of Classic Policies 2. In the details view, click Add. 3. In the Create Application Firewall Profile dialog box, create a Web Application profile with advanced defaults and name it pr_xssokay. Click Create and then click Close. 4. In the details view, click the profile, click Open, and in the Configure Web Application Profile dialog box, configure the pr_xssokay profile as shown below. Start URL Check: Clear all actions. Cookie Consistency Check: Disable blocking. Form Field Consistency Check: Disable blocking. Cross-Site Scripting Check: Disable blocking. This should prevent blocking of legitimate requests involving Web pages with crosssite scripting that you know are nonetheless safe. 5. Click Policies, and then click Add. 6. In the Create Application Firewall Policy dialog box, create a policy that detects connections to your scripted Web pages and applies the pr_xssokay profile: Policy name: pol_xssokay Associated profile: pr_xssokay Policy expression: "REQ.HTTP.HEADER URL CONTAINS ^\.pl\?$ || REQ.HTTP.HEADER URL CONTAINS ^\.js$" 7. Globally bind your new policy to put it into effect.
To drop packets from specific IPs by using the NetScaler command line
w To create a DNS policy named pol_ddos_drop that detects connections from hostile networks and drops those packets, type: add dns policy pol_ddos_drop 'client.ip.src.in_subnet(192.168.253.128/25) || client.ip.src.in_subnet(192.168.254.32/27)' -drop YES' For the example networks in the 192.168.0.0/16 range, you substitute the IP and netmask in ###.###.###.###/## format of each network you want to block. You 452
Citrix NetScaler Policy Configuration and Reference Guide can include as many networks as you want, separating each CLIENT.IP.SRC.IN_SUBNET(###.###.###.###./##) command with the OR operator. w Globally bind your new policy to put it into effect.
453