1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* See the file NOTICE for conditions of use and distribution. */
10 #include "rf_functions.h"
11 #include "ipliteral.h"
14 /* Options specific to the ipliteral router. Because some compilers do not like
15 empty declarations ("undefined" in the Standard) we put in a dummy value. */
17 optionlist ipliteral_router_options[] = {
18 { "", opt_hidden, NULL }
21 /* Size of the options list. An extern variable has to be used so that its
22 address can appear in the tables drtables.c. */
24 int ipliteral_router_options_count =
25 sizeof(ipliteral_router_options)/sizeof(optionlist);
27 /* Default private options block for the ipliteral router. Again, a dummy
28 value is present to keep some compilers happy. */
30 ipliteral_router_options_block ipliteral_router_option_defaults = { 0 };
34 /*************************************************
35 * Initialization entry point *
36 *************************************************/
38 /* Called for each instance, after its options have been read, to enable
39 consistency checks to be done, or anything else that needs to be set up. */
42 ipliteral_router_init(router_instance *rblock)
45 ipliteral_router_options_block *ob =
46 (ipliteral_router_options_block *)(rblock->options_block);
53 /*************************************************
55 *************************************************/
57 /* See local README for interface details. This router returns:
60 . the domain is not in the form of an IP literal
63 . verifying the errors address caused a deferment or a big disaster such
64 as an expansion failure (rf_get_errors_address)
65 . expanding a headers_{add,remove} string caused a deferment or another
66 expansion error (rf_get_munge_headers)
67 . a problem in rf_get_transport: no transport when one is needed;
68 failed to expand dynamic transport; failed to find dynamic transport
69 . failure to expand or find a uid/gid (rf_get_ugid via rf_queue_add)
70 . self = "freeze", self = "defer"
82 added address to addr_local or addr_remote, as appropriate for the
83 type of transport; this includes the self="send" case.
87 ipliteral_router_entry(
88 router_instance *rblock, /* data for this instantiation */
89 address_item *addr, /* address we are working on */
90 struct passwd *pw, /* passwd entry after check_local_user */
91 int verify, /* v_none/v_recipient/v_sender/v_expn */
92 address_item **addr_local, /* add it to this if it's local */
93 address_item **addr_remote, /* add it to this if it's remote */
94 address_item **addr_new, /* put new addresses on here */
95 address_item **addr_succeed) /* put old address here on success */
98 ipliteral_router_options_block *ob =
99 (ipliteral_router_options_block *)(rblock->options_block);
102 uschar *domain = addr->domain;
104 int len = Ustrlen(domain);
107 addr_new = addr_new; /* Keep picky compilers happy */
108 addr_succeed = addr_succeed;
110 DEBUG(D_route) debug_printf("%s router called for %s: domain = %s\n",
111 rblock->name, addr->address, addr->domain);
113 /* Check that the domain is an IP address enclosed in square brackets. Remember
114 to allow for the "official" form of IPv6 addresses. If not, the router
115 declines. Otherwise route to the single IP address, setting the host name to
118 if (domain[0] != '[' || domain[len-1] != ']') return DECLINE;
119 domain[len-1] = 0; /* temporarily */
122 if (strncmpic(ip, US"IPV6:", 5) == 0 || strncmpic(ip, US"IPV4:", 5) == 0)
125 ipv = string_is_ip_address(ip, NULL);
126 if (ipv == 0 || (disable_ipv6 && ipv == 6))
132 /* It seems unlikely that ignore_target_hosts will be used with this router,
133 but if it is set, it should probably work. */
135 if (verify_check_this_host(&(rblock->ignore_target_hosts), NULL, domain,
139 debug_printf("%s is in ignore_target_hosts\n", ip);
140 addr->message = US"IP literal host explicitly ignored";
145 /* Set up a host item */
147 h = store_get(sizeof(host_item));
150 h->address = string_copy(ip);
152 domain[len-1] = ']'; /* restore */
153 h->name = string_copy(domain);
155 h->status = hstatus_unknown;
156 h->why = hwhy_unknown;
159 /* Determine whether the host is the local host, and if so, take action
160 according to the configuration. */
162 if (host_scan_for_local_hosts(h, &h, NULL) == HOST_FOUND_LOCAL)
164 int rc = rf_self_action(addr, h, rblock->self_code, rblock->self_rewrite,
165 rblock->self, addr_new);
166 if (rc != OK) return rc;
169 /* Address is routed to this host */
173 /* Set up the errors address, if any. */
175 rc = rf_get_errors_address(addr, rblock, verify, &(addr->p.errors_address));
176 if (rc != OK) return rc;
178 /* Set up the additional and removeable headers for this address. */
180 rc = rf_get_munge_headers(addr, rblock, &(addr->p.extra_headers),
181 &(addr->p.remove_headers));
182 if (rc != OK) return rc;
184 /* Fill in the transport, queue the address for local or remote delivery, and
185 yield success. For local delivery, of course, the IP address won't be used. If
186 just verifying, there need not be a transport, in which case it doesn't matter
187 which queue we put the address on. This is all now handled by the route_queue()
190 if (!rf_get_transport(rblock->transport_name, &(rblock->transport),
191 addr, rblock->name, NULL))
194 addr->transport = rblock->transport;
196 return rf_queue_add(addr, addr_local, addr_remote, rblock, pw)?
200 /* End of routers/ipliteral.c */