1/* Copyright (c) 2007 MySQL AB, 2008 Sun Microsystems, Inc.
2 Use is subject to license terms.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#ifndef RPL_CONSTANTS_H
18#define RPL_CONSTANTS_H
19
20#include <my_sys.h>
21#include <my_crypt.h>
22
23/**
24 Enumeration of the incidents that can occur for the server.
25 */
26enum Incident {
27 /** No incident */
28 INCIDENT_NONE = 0,
29
30 /** There are possibly lost events in the replication stream */
31 INCIDENT_LOST_EVENTS = 1,
32
33 /** Shall be last event of the enumeration */
34 INCIDENT_COUNT
35};
36
37
38/**
39 Enumeration of the reserved formats of Binlog extra row information
40*/
41enum ExtraRowInfoFormat {
42
43 /** Reserved formats 0 -> 63 inclusive */
44 ERIF_LASTRESERVED = 63,
45
46 /**
47 Available / uncontrolled formats
48 64 -> 254 inclusive
49 */
50 ERIF_OPEN1 = 64,
51 ERIF_OPEN2 = 65,
52
53 ERIF_LASTOPEN = 254,
54
55 /**
56 Multi-payload format 255
57
58 Length is total length, payload is sequence of
59 sub-payloads with their own headers containing
60 length + format.
61 */
62 ERIF_MULTI = 255
63};
64
65/*
66 1 byte length, 1 byte format
67 Length is total length in bytes, including 2 byte header
68 Length values 0 and 1 are currently invalid and reserved.
69*/
70#define EXTRA_ROW_INFO_LEN_OFFSET 0
71#define EXTRA_ROW_INFO_FORMAT_OFFSET 1
72#define EXTRA_ROW_INFO_HDR_BYTES 2
73#define EXTRA_ROW_INFO_MAX_PAYLOAD (255 - EXTRA_ROW_INFO_HDR_BYTES)
74
75enum enum_binlog_checksum_alg {
76 BINLOG_CHECKSUM_ALG_OFF= 0, // Events are without checksum though its generator
77 // is checksum-capable New Master (NM).
78 BINLOG_CHECKSUM_ALG_CRC32= 1, // CRC32 of zlib algorithm.
79 BINLOG_CHECKSUM_ALG_ENUM_END, // the cut line: valid alg range is [1, 0x7f].
80 BINLOG_CHECKSUM_ALG_UNDEF= 255 // special value to tag undetermined yet checksum
81 // or events from checksum-unaware servers
82};
83
84#define BINLOG_CRYPTO_SCHEME_LENGTH 1
85#define BINLOG_KEY_VERSION_LENGTH 4
86#define BINLOG_IV_LENGTH MY_AES_BLOCK_SIZE
87#define BINLOG_IV_OFFS_LENGTH 4
88#define BINLOG_NONCE_LENGTH (BINLOG_IV_LENGTH - BINLOG_IV_OFFS_LENGTH)
89
90struct Binlog_crypt_data {
91 uint scheme;
92 uint key_version, key_length, ctx_size;
93 uchar key[MY_AES_MAX_KEY_LENGTH];
94 uchar nonce[BINLOG_NONCE_LENGTH];
95
96 int init(uint sch, uint kv)
97 {
98 scheme= sch;
99 ctx_size= encryption_ctx_size(ENCRYPTION_KEY_SYSTEM_DATA, kv);
100 key_version= kv;
101 key_length= sizeof(key);
102 return encryption_key_get(ENCRYPTION_KEY_SYSTEM_DATA, kv, key, &key_length);
103 }
104
105 void set_iv(uchar* iv, uint32 offs) const
106 {
107 memcpy(iv, nonce, BINLOG_NONCE_LENGTH);
108 int4store(iv + BINLOG_NONCE_LENGTH, offs);
109 }
110};
111
112#endif /* RPL_CONSTANTS_H */
113