0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #ifndef _TIPC_MSG_H
0038 #define _TIPC_MSG_H
0039
0040 #include <linux/tipc.h>
0041 #include "core.h"
0042
0043
0044
0045
0046
0047
0048 #define TIPC_VERSION 2
0049 struct plist;
0050
0051
0052
0053
0054
0055
0056
0057
0058 #define TIPC_SYSTEM_IMPORTANCE 4
0059
0060
0061
0062
0063
0064 #define TIPC_CONN_MSG 0
0065 #define TIPC_MCAST_MSG 1
0066 #define TIPC_NAMED_MSG 2
0067 #define TIPC_DIRECT_MSG 3
0068 #define TIPC_GRP_MEMBER_EVT 4
0069 #define TIPC_GRP_BCAST_MSG 5
0070 #define TIPC_GRP_MCAST_MSG 6
0071 #define TIPC_GRP_UCAST_MSG 7
0072
0073
0074
0075
0076 #define BCAST_PROTOCOL 5
0077 #define MSG_BUNDLER 6
0078 #define LINK_PROTOCOL 7
0079 #define CONN_MANAGER 8
0080 #define GROUP_PROTOCOL 9
0081 #define TUNNEL_PROTOCOL 10
0082 #define NAME_DISTRIBUTOR 11
0083 #define MSG_FRAGMENTER 12
0084 #define LINK_CONFIG 13
0085 #define MSG_CRYPTO 14
0086 #define SOCK_WAKEUP 14
0087 #define TOP_SRV 15
0088
0089
0090
0091
0092 #define SHORT_H_SIZE 24
0093 #define BASIC_H_SIZE 32
0094 #define NAMED_H_SIZE 40
0095 #define MCAST_H_SIZE 44
0096 #define GROUP_H_SIZE 44
0097 #define INT_H_SIZE 40
0098 #define MIN_H_SIZE 24
0099 #define MAX_H_SIZE 60
0100
0101 #define MAX_MSG_SIZE (MAX_H_SIZE + TIPC_MAX_USER_MSG_SIZE)
0102 #define TIPC_MEDIA_INFO_OFFSET 5
0103
0104 extern const int one_page_mtu;
0105
0106 struct tipc_skb_cb {
0107 union {
0108 struct {
0109 struct sk_buff *tail;
0110 unsigned long nxt_retr;
0111 unsigned long retr_stamp;
0112 u32 bytes_read;
0113 u32 orig_member;
0114 u16 chain_imp;
0115 u16 ackers;
0116 u16 retr_cnt;
0117 } __packed;
0118 #ifdef CONFIG_TIPC_CRYPTO
0119 struct {
0120 struct tipc_crypto *rx;
0121 struct tipc_aead *last;
0122 u8 recurs;
0123 } tx_clone_ctx __packed;
0124 #endif
0125 } __packed;
0126 union {
0127 struct {
0128 u8 validated:1;
0129 #ifdef CONFIG_TIPC_CRYPTO
0130 u8 encrypted:1;
0131 u8 decrypted:1;
0132 #define SKB_PROBING 1
0133 #define SKB_GRACING 2
0134 u8 xmit_type:2;
0135 u8 tx_clone_deferred:1;
0136 #endif
0137 };
0138 u8 flags;
0139 };
0140 u8 reserved;
0141 #ifdef CONFIG_TIPC_CRYPTO
0142 void *crypto_ctx;
0143 #endif
0144 } __packed;
0145
0146 #define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0]))
0147
0148 struct tipc_msg {
0149 __be32 hdr[15];
0150 };
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 struct tipc_gap_ack {
0161 __be16 ack;
0162 __be16 gap;
0163 };
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186 struct tipc_gap_ack_blks {
0187 __be16 len;
0188 union {
0189 u8 ugack_cnt;
0190 u8 start_index;
0191 };
0192 u8 bgack_cnt;
0193 struct tipc_gap_ack gacks[];
0194 };
0195
0196 #define MAX_GAP_ACK_BLKS 128
0197 #define MAX_GAP_ACK_BLKS_SZ (sizeof(struct tipc_gap_ack_blks) + \
0198 sizeof(struct tipc_gap_ack) * MAX_GAP_ACK_BLKS)
0199
0200 static inline struct tipc_msg *buf_msg(struct sk_buff *skb)
0201 {
0202 return (struct tipc_msg *)skb->data;
0203 }
0204
0205 static inline u32 msg_word(struct tipc_msg *m, u32 pos)
0206 {
0207 return ntohl(m->hdr[pos]);
0208 }
0209
0210 static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val)
0211 {
0212 m->hdr[w] = htonl(val);
0213 }
0214
0215 static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask)
0216 {
0217 return (msg_word(m, w) >> pos) & mask;
0218 }
0219
0220 static inline void msg_set_bits(struct tipc_msg *m, u32 w,
0221 u32 pos, u32 mask, u32 val)
0222 {
0223 val = (val & mask) << pos;
0224 mask = mask << pos;
0225 m->hdr[w] &= ~htonl(mask);
0226 m->hdr[w] |= htonl(val);
0227 }
0228
0229
0230
0231
0232 static inline u32 msg_version(struct tipc_msg *m)
0233 {
0234 return msg_bits(m, 0, 29, 7);
0235 }
0236
0237 static inline void msg_set_version(struct tipc_msg *m)
0238 {
0239 msg_set_bits(m, 0, 29, 7, TIPC_VERSION);
0240 }
0241
0242 static inline u32 msg_user(struct tipc_msg *m)
0243 {
0244 return msg_bits(m, 0, 25, 0xf);
0245 }
0246
0247 static inline u32 msg_isdata(struct tipc_msg *m)
0248 {
0249 return msg_user(m) <= TIPC_CRITICAL_IMPORTANCE;
0250 }
0251
0252 static inline void msg_set_user(struct tipc_msg *m, u32 n)
0253 {
0254 msg_set_bits(m, 0, 25, 0xf, n);
0255 }
0256
0257 static inline u32 msg_hdr_sz(struct tipc_msg *m)
0258 {
0259 return msg_bits(m, 0, 21, 0xf) << 2;
0260 }
0261
0262 static inline void msg_set_hdr_sz(struct tipc_msg *m, u32 n)
0263 {
0264 msg_set_bits(m, 0, 21, 0xf, n>>2);
0265 }
0266
0267 static inline u32 msg_size(struct tipc_msg *m)
0268 {
0269 return msg_bits(m, 0, 0, 0x1ffff);
0270 }
0271
0272 static inline u32 msg_blocks(struct tipc_msg *m)
0273 {
0274 return (msg_size(m) / 1024) + 1;
0275 }
0276
0277 static inline u32 msg_data_sz(struct tipc_msg *m)
0278 {
0279 return msg_size(m) - msg_hdr_sz(m);
0280 }
0281
0282 static inline int msg_non_seq(struct tipc_msg *m)
0283 {
0284 return msg_bits(m, 0, 20, 1);
0285 }
0286
0287 static inline void msg_set_non_seq(struct tipc_msg *m, u32 n)
0288 {
0289 msg_set_bits(m, 0, 20, 1, n);
0290 }
0291
0292 static inline int msg_is_syn(struct tipc_msg *m)
0293 {
0294 return msg_bits(m, 0, 17, 1);
0295 }
0296
0297 static inline void msg_set_syn(struct tipc_msg *m, u32 d)
0298 {
0299 msg_set_bits(m, 0, 17, 1, d);
0300 }
0301
0302 static inline int msg_dest_droppable(struct tipc_msg *m)
0303 {
0304 return msg_bits(m, 0, 19, 1);
0305 }
0306
0307 static inline void msg_set_dest_droppable(struct tipc_msg *m, u32 d)
0308 {
0309 msg_set_bits(m, 0, 19, 1, d);
0310 }
0311
0312 static inline int msg_is_keepalive(struct tipc_msg *m)
0313 {
0314 return msg_bits(m, 0, 19, 1);
0315 }
0316
0317 static inline void msg_set_is_keepalive(struct tipc_msg *m, u32 d)
0318 {
0319 msg_set_bits(m, 0, 19, 1, d);
0320 }
0321
0322 static inline int msg_src_droppable(struct tipc_msg *m)
0323 {
0324 return msg_bits(m, 0, 18, 1);
0325 }
0326
0327 static inline void msg_set_src_droppable(struct tipc_msg *m, u32 d)
0328 {
0329 msg_set_bits(m, 0, 18, 1, d);
0330 }
0331
0332 static inline int msg_ack_required(struct tipc_msg *m)
0333 {
0334 return msg_bits(m, 0, 18, 1);
0335 }
0336
0337 static inline void msg_set_ack_required(struct tipc_msg *m)
0338 {
0339 msg_set_bits(m, 0, 18, 1, 1);
0340 }
0341
0342 static inline int msg_nagle_ack(struct tipc_msg *m)
0343 {
0344 return msg_bits(m, 0, 18, 1);
0345 }
0346
0347 static inline void msg_set_nagle_ack(struct tipc_msg *m)
0348 {
0349 msg_set_bits(m, 0, 18, 1, 1);
0350 }
0351
0352 static inline bool msg_is_rcast(struct tipc_msg *m)
0353 {
0354 return msg_bits(m, 0, 18, 0x1);
0355 }
0356
0357 static inline void msg_set_is_rcast(struct tipc_msg *m, bool d)
0358 {
0359 msg_set_bits(m, 0, 18, 0x1, d);
0360 }
0361
0362 static inline void msg_set_size(struct tipc_msg *m, u32 sz)
0363 {
0364 m->hdr[0] = htonl((msg_word(m, 0) & ~0x1ffff) | sz);
0365 }
0366
0367 static inline unchar *msg_data(struct tipc_msg *m)
0368 {
0369 return ((unchar *)m) + msg_hdr_sz(m);
0370 }
0371
0372 static inline struct tipc_msg *msg_inner_hdr(struct tipc_msg *m)
0373 {
0374 return (struct tipc_msg *)msg_data(m);
0375 }
0376
0377
0378
0379
0380 static inline u32 msg_type(struct tipc_msg *m)
0381 {
0382 return msg_bits(m, 1, 29, 0x7);
0383 }
0384
0385 static inline void msg_set_type(struct tipc_msg *m, u32 n)
0386 {
0387 msg_set_bits(m, 1, 29, 0x7, n);
0388 }
0389
0390 static inline int msg_in_group(struct tipc_msg *m)
0391 {
0392 int mtyp = msg_type(m);
0393
0394 return mtyp >= TIPC_GRP_MEMBER_EVT && mtyp <= TIPC_GRP_UCAST_MSG;
0395 }
0396
0397 static inline bool msg_is_grp_evt(struct tipc_msg *m)
0398 {
0399 return msg_type(m) == TIPC_GRP_MEMBER_EVT;
0400 }
0401
0402 static inline u32 msg_named(struct tipc_msg *m)
0403 {
0404 return msg_type(m) == TIPC_NAMED_MSG;
0405 }
0406
0407 static inline u32 msg_mcast(struct tipc_msg *m)
0408 {
0409 int mtyp = msg_type(m);
0410
0411 return ((mtyp == TIPC_MCAST_MSG) || (mtyp == TIPC_GRP_BCAST_MSG) ||
0412 (mtyp == TIPC_GRP_MCAST_MSG));
0413 }
0414
0415 static inline u32 msg_connected(struct tipc_msg *m)
0416 {
0417 return msg_type(m) == TIPC_CONN_MSG;
0418 }
0419
0420 static inline u32 msg_direct(struct tipc_msg *m)
0421 {
0422 return msg_type(m) == TIPC_DIRECT_MSG;
0423 }
0424
0425 static inline u32 msg_errcode(struct tipc_msg *m)
0426 {
0427 return msg_bits(m, 1, 25, 0xf);
0428 }
0429
0430 static inline void msg_set_errcode(struct tipc_msg *m, u32 err)
0431 {
0432 msg_set_bits(m, 1, 25, 0xf, err);
0433 }
0434
0435 static inline void msg_set_bulk(struct tipc_msg *m)
0436 {
0437 msg_set_bits(m, 1, 28, 0x1, 1);
0438 }
0439
0440 static inline u32 msg_is_bulk(struct tipc_msg *m)
0441 {
0442 return msg_bits(m, 1, 28, 0x1);
0443 }
0444
0445 static inline void msg_set_last_bulk(struct tipc_msg *m)
0446 {
0447 msg_set_bits(m, 1, 27, 0x1, 1);
0448 }
0449
0450 static inline u32 msg_is_last_bulk(struct tipc_msg *m)
0451 {
0452 return msg_bits(m, 1, 27, 0x1);
0453 }
0454
0455 static inline void msg_set_non_legacy(struct tipc_msg *m)
0456 {
0457 msg_set_bits(m, 1, 26, 0x1, 1);
0458 }
0459
0460 static inline u32 msg_is_legacy(struct tipc_msg *m)
0461 {
0462 return !msg_bits(m, 1, 26, 0x1);
0463 }
0464
0465 static inline u32 msg_reroute_cnt(struct tipc_msg *m)
0466 {
0467 return msg_bits(m, 1, 21, 0xf);
0468 }
0469
0470 static inline void msg_incr_reroute_cnt(struct tipc_msg *m)
0471 {
0472 msg_set_bits(m, 1, 21, 0xf, msg_reroute_cnt(m) + 1);
0473 }
0474
0475 static inline u32 msg_lookup_scope(struct tipc_msg *m)
0476 {
0477 return msg_bits(m, 1, 19, 0x3);
0478 }
0479
0480 static inline void msg_set_lookup_scope(struct tipc_msg *m, u32 n)
0481 {
0482 msg_set_bits(m, 1, 19, 0x3, n);
0483 }
0484
0485 static inline u16 msg_bcast_ack(struct tipc_msg *m)
0486 {
0487 return msg_bits(m, 1, 0, 0xffff);
0488 }
0489
0490 static inline void msg_set_bcast_ack(struct tipc_msg *m, u16 n)
0491 {
0492 msg_set_bits(m, 1, 0, 0xffff, n);
0493 }
0494
0495
0496
0497
0498 static inline bool msg_dest_session_valid(struct tipc_msg *m)
0499 {
0500 return msg_bits(m, 1, 16, 0x1);
0501 }
0502
0503 static inline void msg_set_dest_session_valid(struct tipc_msg *m, bool valid)
0504 {
0505 msg_set_bits(m, 1, 16, 0x1, valid);
0506 }
0507
0508 static inline u16 msg_dest_session(struct tipc_msg *m)
0509 {
0510 return msg_bits(m, 1, 0, 0xffff);
0511 }
0512
0513 static inline void msg_set_dest_session(struct tipc_msg *m, u16 n)
0514 {
0515 msg_set_bits(m, 1, 0, 0xffff, n);
0516 }
0517
0518
0519
0520
0521 static inline u16 msg_ack(struct tipc_msg *m)
0522 {
0523 return msg_bits(m, 2, 16, 0xffff);
0524 }
0525
0526 static inline void msg_set_ack(struct tipc_msg *m, u16 n)
0527 {
0528 msg_set_bits(m, 2, 16, 0xffff, n);
0529 }
0530
0531 static inline u16 msg_seqno(struct tipc_msg *m)
0532 {
0533 return msg_bits(m, 2, 0, 0xffff);
0534 }
0535
0536 static inline void msg_set_seqno(struct tipc_msg *m, u16 n)
0537 {
0538 msg_set_bits(m, 2, 0, 0xffff, n);
0539 }
0540
0541
0542
0543
0544 static inline u32 msg_importance(struct tipc_msg *m)
0545 {
0546 int usr = msg_user(m);
0547
0548 if (likely((usr <= TIPC_CRITICAL_IMPORTANCE) && !msg_errcode(m)))
0549 return usr;
0550 if ((usr == MSG_FRAGMENTER) || (usr == MSG_BUNDLER))
0551 return msg_bits(m, 9, 0, 0x7);
0552 return TIPC_SYSTEM_IMPORTANCE;
0553 }
0554
0555 static inline void msg_set_importance(struct tipc_msg *m, u32 i)
0556 {
0557 int usr = msg_user(m);
0558
0559 if (likely((usr == MSG_FRAGMENTER) || (usr == MSG_BUNDLER)))
0560 msg_set_bits(m, 9, 0, 0x7, i);
0561 else if (i < TIPC_SYSTEM_IMPORTANCE)
0562 msg_set_user(m, i);
0563 else
0564 pr_warn("Trying to set illegal importance in message\n");
0565 }
0566
0567 static inline u32 msg_prevnode(struct tipc_msg *m)
0568 {
0569 return msg_word(m, 3);
0570 }
0571
0572 static inline void msg_set_prevnode(struct tipc_msg *m, u32 a)
0573 {
0574 msg_set_word(m, 3, a);
0575 }
0576
0577 static inline u32 msg_origport(struct tipc_msg *m)
0578 {
0579 if (msg_user(m) == MSG_FRAGMENTER)
0580 m = msg_inner_hdr(m);
0581 return msg_word(m, 4);
0582 }
0583
0584 static inline void msg_set_origport(struct tipc_msg *m, u32 p)
0585 {
0586 msg_set_word(m, 4, p);
0587 }
0588
0589 static inline u16 msg_named_seqno(struct tipc_msg *m)
0590 {
0591 return msg_bits(m, 4, 0, 0xffff);
0592 }
0593
0594 static inline void msg_set_named_seqno(struct tipc_msg *m, u16 n)
0595 {
0596 msg_set_bits(m, 4, 0, 0xffff, n);
0597 }
0598
0599 static inline u32 msg_destport(struct tipc_msg *m)
0600 {
0601 return msg_word(m, 5);
0602 }
0603
0604 static inline void msg_set_destport(struct tipc_msg *m, u32 p)
0605 {
0606 msg_set_word(m, 5, p);
0607 }
0608
0609 static inline u32 msg_mc_netid(struct tipc_msg *m)
0610 {
0611 return msg_word(m, 5);
0612 }
0613
0614 static inline void msg_set_mc_netid(struct tipc_msg *m, u32 p)
0615 {
0616 msg_set_word(m, 5, p);
0617 }
0618
0619 static inline int msg_short(struct tipc_msg *m)
0620 {
0621 return msg_hdr_sz(m) == SHORT_H_SIZE;
0622 }
0623
0624 static inline u32 msg_orignode(struct tipc_msg *m)
0625 {
0626 if (likely(msg_short(m)))
0627 return msg_prevnode(m);
0628 return msg_word(m, 6);
0629 }
0630
0631 static inline void msg_set_orignode(struct tipc_msg *m, u32 a)
0632 {
0633 msg_set_word(m, 6, a);
0634 }
0635
0636 static inline u32 msg_destnode(struct tipc_msg *m)
0637 {
0638 return msg_word(m, 7);
0639 }
0640
0641 static inline void msg_set_destnode(struct tipc_msg *m, u32 a)
0642 {
0643 msg_set_word(m, 7, a);
0644 }
0645
0646 static inline u32 msg_nametype(struct tipc_msg *m)
0647 {
0648 return msg_word(m, 8);
0649 }
0650
0651 static inline void msg_set_nametype(struct tipc_msg *m, u32 n)
0652 {
0653 msg_set_word(m, 8, n);
0654 }
0655
0656 static inline u32 msg_nameinst(struct tipc_msg *m)
0657 {
0658 return msg_word(m, 9);
0659 }
0660
0661 static inline u32 msg_namelower(struct tipc_msg *m)
0662 {
0663 return msg_nameinst(m);
0664 }
0665
0666 static inline void msg_set_namelower(struct tipc_msg *m, u32 n)
0667 {
0668 msg_set_word(m, 9, n);
0669 }
0670
0671 static inline void msg_set_nameinst(struct tipc_msg *m, u32 n)
0672 {
0673 msg_set_namelower(m, n);
0674 }
0675
0676 static inline u32 msg_nameupper(struct tipc_msg *m)
0677 {
0678 return msg_word(m, 10);
0679 }
0680
0681 static inline void msg_set_nameupper(struct tipc_msg *m, u32 n)
0682 {
0683 msg_set_word(m, 10, n);
0684 }
0685
0686
0687
0688
0689
0690
0691
0692
0693 #define CONN_PROBE 0
0694 #define CONN_PROBE_REPLY 1
0695 #define CONN_ACK 2
0696
0697
0698
0699
0700 #define PUBLICATION 0
0701 #define WITHDRAWAL 1
0702
0703
0704
0705
0706 #define FIRST_FRAGMENT 0
0707 #define FRAGMENT 1
0708 #define LAST_FRAGMENT 2
0709
0710
0711
0712
0713 #define STATE_MSG 0
0714 #define RESET_MSG 1
0715 #define ACTIVATE_MSG 2
0716
0717
0718
0719
0720 #define SYNCH_MSG 0
0721 #define FAILOVER_MSG 1
0722
0723
0724
0725
0726 #define DSC_REQ_MSG 0
0727 #define DSC_RESP_MSG 1
0728 #define DSC_TRIAL_MSG 2
0729 #define DSC_TRIAL_FAIL_MSG 3
0730
0731
0732
0733
0734 #define GRP_JOIN_MSG 0
0735 #define GRP_LEAVE_MSG 1
0736 #define GRP_ADV_MSG 2
0737 #define GRP_ACK_MSG 3
0738 #define GRP_RECLAIM_MSG 4
0739 #define GRP_REMIT_MSG 5
0740
0741
0742 #define KEY_DISTR_MSG 0
0743
0744
0745
0746
0747 static inline u32 msg_seq_gap(struct tipc_msg *m)
0748 {
0749 return msg_bits(m, 1, 16, 0x1fff);
0750 }
0751
0752 static inline void msg_set_seq_gap(struct tipc_msg *m, u32 n)
0753 {
0754 msg_set_bits(m, 1, 16, 0x1fff, n);
0755 }
0756
0757 static inline u32 msg_node_sig(struct tipc_msg *m)
0758 {
0759 return msg_bits(m, 1, 0, 0xffff);
0760 }
0761
0762 static inline void msg_set_node_sig(struct tipc_msg *m, u32 n)
0763 {
0764 msg_set_bits(m, 1, 0, 0xffff, n);
0765 }
0766
0767 static inline u32 msg_node_capabilities(struct tipc_msg *m)
0768 {
0769 return msg_bits(m, 1, 15, 0x1fff);
0770 }
0771
0772 static inline void msg_set_node_capabilities(struct tipc_msg *m, u32 n)
0773 {
0774 msg_set_bits(m, 1, 15, 0x1fff, n);
0775 }
0776
0777
0778
0779
0780 static inline u32 msg_dest_domain(struct tipc_msg *m)
0781 {
0782 return msg_word(m, 2);
0783 }
0784
0785 static inline void msg_set_dest_domain(struct tipc_msg *m, u32 n)
0786 {
0787 msg_set_word(m, 2, n);
0788 }
0789
0790 static inline void msg_set_bcgap_after(struct tipc_msg *m, u32 n)
0791 {
0792 msg_set_bits(m, 2, 16, 0xffff, n);
0793 }
0794
0795 static inline u32 msg_bcgap_to(struct tipc_msg *m)
0796 {
0797 return msg_bits(m, 2, 0, 0xffff);
0798 }
0799
0800 static inline void msg_set_bcgap_to(struct tipc_msg *m, u32 n)
0801 {
0802 msg_set_bits(m, 2, 0, 0xffff, n);
0803 }
0804
0805
0806
0807
0808 static inline u32 msg_last_bcast(struct tipc_msg *m)
0809 {
0810 return msg_bits(m, 4, 16, 0xffff);
0811 }
0812
0813 static inline u32 msg_bc_snd_nxt(struct tipc_msg *m)
0814 {
0815 return msg_last_bcast(m) + 1;
0816 }
0817
0818 static inline void msg_set_last_bcast(struct tipc_msg *m, u32 n)
0819 {
0820 msg_set_bits(m, 4, 16, 0xffff, n);
0821 }
0822
0823 static inline u32 msg_nof_fragms(struct tipc_msg *m)
0824 {
0825 return msg_bits(m, 4, 0, 0xffff);
0826 }
0827
0828 static inline void msg_set_nof_fragms(struct tipc_msg *m, u32 n)
0829 {
0830 msg_set_bits(m, 4, 0, 0xffff, n);
0831 }
0832
0833 static inline u32 msg_fragm_no(struct tipc_msg *m)
0834 {
0835 return msg_bits(m, 4, 16, 0xffff);
0836 }
0837
0838 static inline void msg_set_fragm_no(struct tipc_msg *m, u32 n)
0839 {
0840 msg_set_bits(m, 4, 16, 0xffff, n);
0841 }
0842
0843 static inline u16 msg_next_sent(struct tipc_msg *m)
0844 {
0845 return msg_bits(m, 4, 0, 0xffff);
0846 }
0847
0848 static inline void msg_set_next_sent(struct tipc_msg *m, u16 n)
0849 {
0850 msg_set_bits(m, 4, 0, 0xffff, n);
0851 }
0852
0853 static inline u32 msg_bc_netid(struct tipc_msg *m)
0854 {
0855 return msg_word(m, 4);
0856 }
0857
0858 static inline void msg_set_bc_netid(struct tipc_msg *m, u32 id)
0859 {
0860 msg_set_word(m, 4, id);
0861 }
0862
0863 static inline u32 msg_link_selector(struct tipc_msg *m)
0864 {
0865 if (msg_user(m) == MSG_FRAGMENTER)
0866 m = (void *)msg_data(m);
0867 return msg_bits(m, 4, 0, 1);
0868 }
0869
0870
0871
0872
0873 static inline u16 msg_session(struct tipc_msg *m)
0874 {
0875 return msg_bits(m, 5, 16, 0xffff);
0876 }
0877
0878 static inline void msg_set_session(struct tipc_msg *m, u16 n)
0879 {
0880 msg_set_bits(m, 5, 16, 0xffff, n);
0881 }
0882
0883 static inline u32 msg_probe(struct tipc_msg *m)
0884 {
0885 return msg_bits(m, 5, 0, 1);
0886 }
0887
0888 static inline void msg_set_probe(struct tipc_msg *m, u32 val)
0889 {
0890 msg_set_bits(m, 5, 0, 1, val);
0891 }
0892
0893 static inline char msg_net_plane(struct tipc_msg *m)
0894 {
0895 return msg_bits(m, 5, 1, 7) + 'A';
0896 }
0897
0898 static inline void msg_set_net_plane(struct tipc_msg *m, char n)
0899 {
0900 msg_set_bits(m, 5, 1, 7, (n - 'A'));
0901 }
0902
0903 static inline u32 msg_linkprio(struct tipc_msg *m)
0904 {
0905 return msg_bits(m, 5, 4, 0x1f);
0906 }
0907
0908 static inline void msg_set_linkprio(struct tipc_msg *m, u32 n)
0909 {
0910 msg_set_bits(m, 5, 4, 0x1f, n);
0911 }
0912
0913 static inline u32 msg_bearer_id(struct tipc_msg *m)
0914 {
0915 return msg_bits(m, 5, 9, 0x7);
0916 }
0917
0918 static inline void msg_set_bearer_id(struct tipc_msg *m, u32 n)
0919 {
0920 msg_set_bits(m, 5, 9, 0x7, n);
0921 }
0922
0923 static inline u32 msg_redundant_link(struct tipc_msg *m)
0924 {
0925 return msg_bits(m, 5, 12, 0x1);
0926 }
0927
0928 static inline void msg_set_redundant_link(struct tipc_msg *m, u32 r)
0929 {
0930 msg_set_bits(m, 5, 12, 0x1, r);
0931 }
0932
0933 static inline u32 msg_peer_stopping(struct tipc_msg *m)
0934 {
0935 return msg_bits(m, 5, 13, 0x1);
0936 }
0937
0938 static inline void msg_set_peer_stopping(struct tipc_msg *m, u32 s)
0939 {
0940 msg_set_bits(m, 5, 13, 0x1, s);
0941 }
0942
0943 static inline bool msg_bc_ack_invalid(struct tipc_msg *m)
0944 {
0945 switch (msg_user(m)) {
0946 case BCAST_PROTOCOL:
0947 case NAME_DISTRIBUTOR:
0948 case LINK_PROTOCOL:
0949 return msg_bits(m, 5, 14, 0x1);
0950 default:
0951 return false;
0952 }
0953 }
0954
0955 static inline void msg_set_bc_ack_invalid(struct tipc_msg *m, bool invalid)
0956 {
0957 msg_set_bits(m, 5, 14, 0x1, invalid);
0958 }
0959
0960 static inline char *msg_media_addr(struct tipc_msg *m)
0961 {
0962 return (char *)&m->hdr[TIPC_MEDIA_INFO_OFFSET];
0963 }
0964
0965 static inline u32 msg_bc_gap(struct tipc_msg *m)
0966 {
0967 return msg_bits(m, 8, 0, 0x3ff);
0968 }
0969
0970 static inline void msg_set_bc_gap(struct tipc_msg *m, u32 n)
0971 {
0972 msg_set_bits(m, 8, 0, 0x3ff, n);
0973 }
0974
0975
0976
0977
0978 static inline u16 msg_msgcnt(struct tipc_msg *m)
0979 {
0980 return msg_bits(m, 9, 16, 0xffff);
0981 }
0982
0983 static inline void msg_set_msgcnt(struct tipc_msg *m, u16 n)
0984 {
0985 msg_set_bits(m, 9, 16, 0xffff, n);
0986 }
0987
0988 static inline u16 msg_syncpt(struct tipc_msg *m)
0989 {
0990 return msg_bits(m, 9, 16, 0xffff);
0991 }
0992
0993 static inline void msg_set_syncpt(struct tipc_msg *m, u16 n)
0994 {
0995 msg_set_bits(m, 9, 16, 0xffff, n);
0996 }
0997
0998 static inline u32 msg_conn_ack(struct tipc_msg *m)
0999 {
1000 return msg_bits(m, 9, 16, 0xffff);
1001 }
1002
1003 static inline void msg_set_conn_ack(struct tipc_msg *m, u32 n)
1004 {
1005 msg_set_bits(m, 9, 16, 0xffff, n);
1006 }
1007
1008 static inline u16 msg_adv_win(struct tipc_msg *m)
1009 {
1010 return msg_bits(m, 9, 0, 0xffff);
1011 }
1012
1013 static inline void msg_set_adv_win(struct tipc_msg *m, u16 n)
1014 {
1015 msg_set_bits(m, 9, 0, 0xffff, n);
1016 }
1017
1018 static inline u32 msg_max_pkt(struct tipc_msg *m)
1019 {
1020 return msg_bits(m, 9, 16, 0xffff) * 4;
1021 }
1022
1023 static inline void msg_set_max_pkt(struct tipc_msg *m, u32 n)
1024 {
1025 msg_set_bits(m, 9, 16, 0xffff, (n / 4));
1026 }
1027
1028 static inline u32 msg_link_tolerance(struct tipc_msg *m)
1029 {
1030 return msg_bits(m, 9, 0, 0xffff);
1031 }
1032
1033 static inline void msg_set_link_tolerance(struct tipc_msg *m, u32 n)
1034 {
1035 msg_set_bits(m, 9, 0, 0xffff, n);
1036 }
1037
1038 static inline u16 msg_grp_bc_syncpt(struct tipc_msg *m)
1039 {
1040 return msg_bits(m, 9, 16, 0xffff);
1041 }
1042
1043 static inline void msg_set_grp_bc_syncpt(struct tipc_msg *m, u16 n)
1044 {
1045 msg_set_bits(m, 9, 16, 0xffff, n);
1046 }
1047
1048 static inline u16 msg_grp_bc_acked(struct tipc_msg *m)
1049 {
1050 return msg_bits(m, 9, 16, 0xffff);
1051 }
1052
1053 static inline void msg_set_grp_bc_acked(struct tipc_msg *m, u16 n)
1054 {
1055 msg_set_bits(m, 9, 16, 0xffff, n);
1056 }
1057
1058 static inline u16 msg_grp_remitted(struct tipc_msg *m)
1059 {
1060 return msg_bits(m, 9, 16, 0xffff);
1061 }
1062
1063 static inline void msg_set_grp_remitted(struct tipc_msg *m, u16 n)
1064 {
1065 msg_set_bits(m, 9, 16, 0xffff, n);
1066 }
1067
1068
1069
1070 static inline u16 msg_grp_evt(struct tipc_msg *m)
1071 {
1072 return msg_bits(m, 10, 0, 0x3);
1073 }
1074
1075 static inline void msg_set_grp_evt(struct tipc_msg *m, int n)
1076 {
1077 msg_set_bits(m, 10, 0, 0x3, n);
1078 }
1079
1080 static inline u16 msg_grp_bc_ack_req(struct tipc_msg *m)
1081 {
1082 return msg_bits(m, 10, 0, 0x1);
1083 }
1084
1085 static inline void msg_set_grp_bc_ack_req(struct tipc_msg *m, bool n)
1086 {
1087 msg_set_bits(m, 10, 0, 0x1, n);
1088 }
1089
1090 static inline u16 msg_grp_bc_seqno(struct tipc_msg *m)
1091 {
1092 return msg_bits(m, 10, 16, 0xffff);
1093 }
1094
1095 static inline void msg_set_grp_bc_seqno(struct tipc_msg *m, u32 n)
1096 {
1097 msg_set_bits(m, 10, 16, 0xffff, n);
1098 }
1099
1100 static inline bool msg_peer_link_is_up(struct tipc_msg *m)
1101 {
1102 if (likely(msg_user(m) != LINK_PROTOCOL))
1103 return true;
1104 if (msg_type(m) == STATE_MSG)
1105 return true;
1106 return false;
1107 }
1108
1109 static inline bool msg_peer_node_is_up(struct tipc_msg *m)
1110 {
1111 if (msg_peer_link_is_up(m))
1112 return true;
1113 return msg_redundant_link(m);
1114 }
1115
1116 static inline bool msg_is_reset(struct tipc_msg *hdr)
1117 {
1118 return (msg_user(hdr) == LINK_PROTOCOL) && (msg_type(hdr) == RESET_MSG);
1119 }
1120
1121
1122
1123 static inline void msg_set_peer_net_hash(struct tipc_msg *m, u32 n)
1124 {
1125 msg_set_word(m, 13, n);
1126 }
1127
1128 static inline u32 msg_peer_net_hash(struct tipc_msg *m)
1129 {
1130 return msg_word(m, 13);
1131 }
1132
1133
1134
1135 static inline u32 msg_sugg_node_addr(struct tipc_msg *m)
1136 {
1137 return msg_word(m, 14);
1138 }
1139
1140 static inline void msg_set_sugg_node_addr(struct tipc_msg *m, u32 n)
1141 {
1142 msg_set_word(m, 14, n);
1143 }
1144
1145 static inline void msg_set_node_id(struct tipc_msg *hdr, u8 *id)
1146 {
1147 memcpy(msg_data(hdr), id, 16);
1148 }
1149
1150 static inline u8 *msg_node_id(struct tipc_msg *hdr)
1151 {
1152 return (u8 *)msg_data(hdr);
1153 }
1154
1155 struct sk_buff *tipc_buf_acquire(u32 size, gfp_t gfp);
1156 bool tipc_msg_validate(struct sk_buff **_skb);
1157 bool tipc_msg_reverse(u32 own_addr, struct sk_buff **skb, int err);
1158 void tipc_skb_reject(struct net *net, int err, struct sk_buff *skb,
1159 struct sk_buff_head *xmitq);
1160 void tipc_msg_init(u32 own_addr, struct tipc_msg *m, u32 user, u32 type,
1161 u32 hsize, u32 destnode);
1162 struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz,
1163 uint data_sz, u32 dnode, u32 onode,
1164 u32 dport, u32 oport, int errcode);
1165 int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf);
1166 bool tipc_msg_try_bundle(struct sk_buff *tskb, struct sk_buff **skb, u32 mss,
1167 u32 dnode, bool *new_bundle);
1168 bool tipc_msg_extract(struct sk_buff *skb, struct sk_buff **iskb, int *pos);
1169 int tipc_msg_fragment(struct sk_buff *skb, const struct tipc_msg *hdr,
1170 int pktmax, struct sk_buff_head *frags);
1171 int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m,
1172 int offset, int dsz, int mtu, struct sk_buff_head *list);
1173 int tipc_msg_append(struct tipc_msg *hdr, struct msghdr *m, int dlen,
1174 int mss, struct sk_buff_head *txq);
1175 bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err);
1176 bool tipc_msg_assemble(struct sk_buff_head *list);
1177 bool tipc_msg_reassemble(struct sk_buff_head *list, struct sk_buff_head *rcvq);
1178 bool tipc_msg_pskb_copy(u32 dst, struct sk_buff_head *msg,
1179 struct sk_buff_head *cpy);
1180 bool __tipc_skb_queue_sorted(struct sk_buff_head *list, u16 seqno,
1181 struct sk_buff *skb);
1182 bool tipc_msg_skb_clone(struct sk_buff_head *msg, struct sk_buff_head *cpy);
1183
1184 static inline u16 buf_seqno(struct sk_buff *skb)
1185 {
1186 return msg_seqno(buf_msg(skb));
1187 }
1188
1189 static inline int buf_roundup_len(struct sk_buff *skb)
1190 {
1191 return (skb->len / 1024 + 1) * 1024;
1192 }
1193
1194
1195
1196
1197
1198 static inline struct sk_buff *tipc_skb_peek(struct sk_buff_head *list,
1199 spinlock_t *lock)
1200 {
1201 struct sk_buff *skb;
1202
1203 spin_lock_bh(lock);
1204 skb = skb_peek(list);
1205 if (skb)
1206 skb_get(skb);
1207 spin_unlock_bh(lock);
1208 return skb;
1209 }
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219 static inline u32 tipc_skb_peek_port(struct sk_buff_head *list, u32 filter)
1220 {
1221 struct sk_buff *skb;
1222 u32 dport = 0;
1223 bool ignore = true;
1224
1225 spin_lock_bh(&list->lock);
1226 skb_queue_walk(list, skb) {
1227 dport = msg_destport(buf_msg(skb));
1228 if (!filter || skb_queue_is_last(list, skb))
1229 break;
1230 if (dport == filter)
1231 ignore = false;
1232 else if (!ignore)
1233 break;
1234 }
1235 spin_unlock_bh(&list->lock);
1236 return dport;
1237 }
1238
1239
1240
1241
1242
1243 static inline struct sk_buff *tipc_skb_dequeue(struct sk_buff_head *list,
1244 u32 dport)
1245 {
1246 struct sk_buff *_skb, *tmp, *skb = NULL;
1247
1248 spin_lock_bh(&list->lock);
1249 skb_queue_walk_safe(list, _skb, tmp) {
1250 if (msg_destport(buf_msg(_skb)) == dport) {
1251 __skb_unlink(_skb, list);
1252 skb = _skb;
1253 break;
1254 }
1255 }
1256 spin_unlock_bh(&list->lock);
1257 return skb;
1258 }
1259
1260
1261
1262
1263
1264 static inline void tipc_skb_queue_splice_tail(struct sk_buff_head *list,
1265 struct sk_buff_head *head)
1266 {
1267 spin_lock_bh(&head->lock);
1268 skb_queue_splice_tail(list, head);
1269 spin_unlock_bh(&head->lock);
1270 }
1271
1272
1273
1274
1275
1276 static inline void tipc_skb_queue_splice_tail_init(struct sk_buff_head *list,
1277 struct sk_buff_head *head)
1278 {
1279 struct sk_buff_head tmp;
1280
1281 __skb_queue_head_init(&tmp);
1282
1283 spin_lock_bh(&list->lock);
1284 skb_queue_splice_tail_init(list, &tmp);
1285 spin_unlock_bh(&list->lock);
1286 tipc_skb_queue_splice_tail(&tmp, head);
1287 }
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298 static inline struct sk_buff *__tipc_skb_dequeue(struct sk_buff_head *list,
1299 u16 seqno)
1300 {
1301 struct sk_buff *skb = skb_peek(list);
1302
1303 if (skb && less_eq(buf_seqno(skb), seqno)) {
1304 __skb_unlink(skb, list);
1305 return skb;
1306 }
1307 return NULL;
1308 }
1309
1310 #endif