Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/proto/filters.h |
| 3 | * This file defines function prototypes for stream filters management. |
| 4 | * |
| 5 | * Copyright (C) 2015 Qualys Inc., Christopher Faulet <cfaulet@qualys.com> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | #ifndef _PROTO_FILTERS_H |
| 22 | #define _PROTO_FILTERS_H |
| 23 | |
| 24 | #include <types/channel.h> |
| 25 | #include <types/filters.h> |
| 26 | #include <types/proto_http.h> |
| 27 | #include <types/proxy.h> |
| 28 | #include <types/stream.h> |
| 29 | |
| 30 | #include <proto/channel.h> |
| 31 | |
| 32 | /* Useful macros to access per-channel values. It can be safely used inside |
| 33 | * filters. */ |
| 34 | #define CHN_IDX(chn) (((chn)->flags & CF_ISRESP) == CF_ISRESP) |
| 35 | #define FLT_NXT(flt, chn) ((flt)->next[CHN_IDX(chn)]) |
| 36 | #define FLT_FWD(flt, chn) ((flt)->fwd[CHN_IDX(chn)]) |
| 37 | |
| 38 | extern struct pool_head *pool2_filter; |
| 39 | |
| 40 | int flt_init(struct proxy *p); |
| 41 | void flt_deinit(struct proxy *p); |
| 42 | int flt_check(struct proxy *p); |
| 43 | |
| 44 | int flt_stream_start(struct stream *s); |
| 45 | void flt_stream_stop(struct stream *s); |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame^] | 46 | int flt_set_stream_backend(struct stream *s, struct proxy *be); |
| 47 | int flt_stream_init(struct stream *s); |
| 48 | void flt_stream_release(struct stream *s, int only_backend); |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 49 | |
| 50 | int flt_http_headers(struct stream *s, struct http_msg *msg); |
| 51 | int flt_http_start_chunk(struct stream *s, struct http_msg *msg); |
| 52 | int flt_http_data(struct stream *s, struct http_msg *msg); |
| 53 | int flt_http_last_chunk(struct stream *s, struct http_msg *msg); |
| 54 | int flt_http_end_chunk(struct stream *s, struct http_msg *msg); |
| 55 | int flt_http_chunk_trailers(struct stream *s, struct http_msg *msg); |
| 56 | int flt_http_end(struct stream *s, struct http_msg *msg); |
| 57 | void flt_http_reset(struct stream *s, struct http_msg *msg); |
| 58 | |
| 59 | void flt_http_reply(struct stream *s, short status, const struct chunk *msg); |
| 60 | int flt_http_forward_data(struct stream *s, struct http_msg *msg, unsigned int len); |
| 61 | |
| 62 | int flt_start_analyze(struct stream *s, struct channel *chn, unsigned int an_bit); |
| 63 | int flt_analyze(struct stream *s, struct channel *chn, unsigned int an_bit); |
| 64 | int flt_end_analyze(struct stream *s, struct channel *chn, unsigned int an_bit); |
| 65 | |
| 66 | int flt_xfer_data(struct stream *s, struct channel *chn, unsigned int an_bit); |
| 67 | |
| 68 | void flt_register_keywords(struct flt_kw_list *kwl); |
| 69 | struct flt_kw *flt_find_kw(const char *kw); |
| 70 | void flt_dump_kws(char **out); |
| 71 | |
| 72 | static inline void |
| 73 | flt_set_forward_data(struct filter *filter, struct channel *chn) |
| 74 | { |
| 75 | filter->flags[CHN_IDX(chn)] |= FILTER_FL_FORWARD_DATA; |
| 76 | } |
| 77 | |
| 78 | static inline void |
| 79 | flt_reset_forward_data(struct filter *filter, struct channel *chn) |
| 80 | { |
| 81 | filter->flags[CHN_IDX(chn)] &= ~FILTER_FL_FORWARD_DATA; |
| 82 | } |
| 83 | |
| 84 | static inline int |
| 85 | flt_want_forward_data(struct filter *filter, const struct channel *chn) |
| 86 | { |
| 87 | return filter->flags[CHN_IDX(chn)] & FILTER_FL_FORWARD_DATA; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /* This function must be called when a filter alter incoming data. It updates |
| 92 | * next offset value of all filter's predecessors. Do not call this function |
| 93 | * when a filter change the size of incomding data leads to an undefined |
| 94 | * behavior. |
| 95 | * |
| 96 | * This is the filter's responsiblitiy to update data itself. For now, it is |
| 97 | * unclear to know how to handle data updates, so we do the minimum here. For |
| 98 | * example, if you filter an HTTP message, we must update msg->next and |
| 99 | * msg->chunk_len values. |
| 100 | */ |
| 101 | static inline void |
| 102 | flt_change_next_size(struct filter *filter, struct channel *chn, int len) |
| 103 | { |
| 104 | struct stream *s = chn_strm(chn); |
| 105 | struct filter *f; |
| 106 | |
| 107 | list_for_each_entry(f, &s->strm_flt.filters, list) { |
| 108 | if (f == filter) |
| 109 | break; |
| 110 | FLT_NXT(f, chn) += len; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /* This function must be called when a filter alter forwarded data. It updates |
| 115 | * offset values (next and forward) of all filters. Do not call this function |
| 116 | * when a filter change the size of forwarded data leads to an undefined |
| 117 | * behavior. |
| 118 | * |
| 119 | * This is the filter's responsiblitiy to update data itself. For now, it is |
| 120 | * unclear to know how to handle data updates, so we do the minimum here. For |
| 121 | * example, if you filter an HTTP message, we must update msg->next and |
| 122 | * msg->chunk_len values. |
| 123 | */ |
| 124 | static inline void |
| 125 | flt_change_forward_size(struct filter *filter, struct channel *chn, int len) |
| 126 | { |
| 127 | struct stream *s = chn_strm(chn); |
| 128 | struct filter *f; |
| 129 | int before = 1; |
| 130 | |
| 131 | list_for_each_entry(f, &s->strm_flt.filters, list) { |
| 132 | if (f == filter) |
| 133 | before = 0; |
| 134 | if (before) |
| 135 | FLT_FWD(f, chn) += len; |
| 136 | FLT_NXT(f, chn) += len; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | |
| 141 | #endif /* _PROTO_FILTERS_H */ |